Not working: Must query between array of records in nested type

I have the below record:

{
        "objectId": "ea5f9b14e0ca03990591de06a433a220",
        "annotations": [
            {
                "itemDetails": {
                    "value": "US1",
                    "confidence": 1
                }
            },
            {
                "itemDetails": {
                    "value": "US2",
                    "confidence": 0.9579
                }
            }
        ]
    }

annotations is nested in the above document. and value is keyword in itemDetails.

I am using the below query to fetch this record. But no results found.

{
   "query": {
      "nested": {
         "path": "annotations",
         "query": {
            "bool": {
               "must": [
                  {
                     "match": {
                        "annotations.itemDetails.value": "US1"
                     }
                  },
                  {
                     "match": {
                        "annotations.itemDetails.value": "US2"
                     }
                  }
               ]
            }
         }
      }
   }
}

Need suggestion to understand what I am doing wrong. should operation is working file but not sure whats wrong with the must

Update:
Correct me if I am wrong, From this link https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html, I see must inside the nested record will not work. Page says --> This query doesn’t match because US1 and US2 are not in the same nested object.

Big trouble now. How can I achieve the above by changing the mappings?

Change the must part to a should part, which resembles an OR as long as you do not add a filter/must_not/must part to that bool query.

I found below query solved the problem. But I am mentioning "path" twice here. What are the consequences or issues I face if I do so?

{
    "query": {
        "bool": {
            "must": [
                {
                    "nested": {
                        "path": "annotations",
                        "query": {
                            "bool": {
                                "must": [
                                    {"match": {"annotations.itemDetails.value": "US1"}}
                                ]
                            }
                        }
                    }
                },
                {
                    "nested": {
                        "path": "annotations",
                        "query": {
                            "bool": {
                                "must": [
                                    {"match": {
                                           "annotations.itemDetails.value": "US2"}}
                                ]
                            }
                        }
                    }
                }
            ]
        }
    }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.