DocDB Elastic cannot use regex filter that starts with escape characters

0

Filtering on _id field using regex works fine if the regex does not start with escape characters

db.getCollection('col').aggregate([ { $match: { _id: /^xx/ } } ], {hint: {_id: 1}, explain: true })

But It breaks when the there are escape characters in the beginning:

db.getCollection('col').aggregate([ { $match: { _id: /^\/xx/ } } ], {hint: {_id: 1}, explain: true })

The error is:

- Cannot use Hint for this Query. Index is multi key index or sparse index and query is not optimized to use this index.

Hamid
已提問 7 個月前檢視次數 234 次
1 個回答
0

Hello AWS Customer

From the details provided , kindly allow me to mention it seems in both cases you have provided similar query. Based on the testing in my environment, I can see that query is working and not providing any error.

Testing Details :

Created collection :
rs0:PRIMARY> db.createCollection("mycoll")
{ "ok" : 1, "operationTime" : Timestamp(1698782387, 1) }

Inserted data :

rs0:PRIMARY> db.mycoll.insert({"name":"anushka", "age":54, "Test" : { "Date" : "2023-06-04T02:52:25.638-07:00", "Status" : "Completed" }});
WriteResult({ "nInserted" : 1 })
rs0:PRIMARY> db.mycoll.insert({"name":"joe", "age":45, "Test" : { "Date" : "2023-05-04T02:52:25.638-07:00", "Status" : "Pending" }});
WriteResult({ "nInserted" : 1 })

Find query :

rs0:PRIMARY> db.mycoll.findOne({"name":"joe"});
{
        "_id" : ObjectId("65415cb455a04e2c7cda0bc3"),
        "name" : "joe",
        "age" : 45,
        "Test" : {
                "Date" : "2023-05-04T02:52:25.638-07:00",
                "Status" : "Pending"
        }
}

Running provided query


rs0:PRIMARY> db.getCollection('mycoll').aggregate([ { $match: { _id: /^xx/ } } ], {hint: {_id: 1}, explain: true })
{
        "queryPlanner" : {
                "plannerVersion" : 1,
                "namespace" : "test.mycoll",
                "winningPlan" : {
                        "stage" : "FETCH",
                        "inputStage" : {
                                "stage" : "IXOR",
                                "inputStages" : [
                                        {
                                                "stage" : "IXSCAN",
                                                "indexName" : "_id_"
                                        },
                                        {
                                                "stage" : "IXSCAN",
                                                "indexName" : "_id_"
                                        }
                                ]
                        }
                }
        },
        "serverInfo" : {
                "host" : "checkdb",
                "port" : 27017,
                "version" : "5.0.0"
        },
        "ok" : 1,
        "operationTime" : Timestamp(1698782503, 1)
}

Since complete details are not present their might be few miss in replicating the use case.

To answer your question, we require additional details to replicate your use case for getting better understanding of the issue and help you resolve it. Please open a support case with AWS using the following link [+] https://console.aws.amazon.com/support/home#/case/create

Thank you for your kind patience with us.

AWS
Sonu_S
已回答 6 個月前
  • Thank you, I updated the question, the second statement searches for strings starting with "/xx", I.e the regex contains an escape character in the beginning.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南