0

I want to index an array field, I have the next JSON

{
    "id": "invoice1",
    "sellers": [{
        "names": "Clark",
        "items": [{
            "iditem": "item1",
            "properties": [{
                "width": "212cm"
            }]
        }]
    }]
}

I would like to create an index in width propertie, I already used create index with

{
   "index": {
      "fields": [
         "sellers.[].items.[].properties.[].width"
      ]
   },
   "type": "json"
}

this is the answer in many posts but when I create the above index and when I query a selector

{
   "selector": {
      "sellers": {
         "$elemMatch": {
            "items": {
               "$elemMatch": {
                  "properties": {
                     "$elemMatch": {
                        "width": {
                           "$eq": "212cm"
                        }
                     }
                  }
               }
            }
         }
      }
   }
}

The response is

"warning": "no matching index found, create an index to optimize query time"
Julian Solarte
  • 495
  • 5
  • 24
  • Possible duplicate of [Mango search in Arrays](https://stackoverflow.com/questions/43892556/mango-search-in-arrays) – Flimzy Jul 12 '19 at 08:00
  • I am doing and I did the same in the referenced post but the answer is the same..."warning": "no matching index found, create an index to optimize query time" – Julian Solarte Jul 12 '19 at 13:40
  • Can you try changing your query to have a single $elemMatch on `sellers.[].items.[].properties.[].width` ? – Alexis Côté Jul 12 '19 at 15:35
  • Sorry, it was a typo, I already try using a dot sellers.[].items.[].properties.[].width – Julian Solarte Jul 12 '19 at 16:34

0 Answers0