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.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠