Searching two terms inside array of object

"rno" : 1,
"narratives": [
            {
              "compl": "call drop",
              "ts": "2015-05-01"
            },
            {
              "compl": "internet connection lost ",
              "ts": "2016-01-15"
            },
            {
              "compl": "water problem ",
              "ts": "2016-01-20"
            }
          ]

need to write query which can search "call" and "lost" in the narrative field.
i tried match, must and rest but both are not working on array of object.

Hi @yashveer

If your field is nested type you need to use nested query.

{
  "query": {
    "nested": {
      "path": "narratives",
      "query": {
        "match": {
          "narratives.compl": "call lost"
        }
      }, "inner_hits": {}
    }
  }
}

Hi @RabBit_BR

this query using OR operator and returning records with either call or lost or both. but i need to return records which has both of the keywords like "call and lost".

you can use operator and.

"match": {
          "narratives.compl": "call lost",
          "operator": "AND"
        }

@RabBit_BR

we cant use operator with match, operator "and" is allowed with query. more over it will try to search both terms together in the same field. which is again not the case.

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