How to nested and other field search

Hello!
I want to know about the search conditions.

{
  "query": {
    "nested": {
      "path": "others",
      "query": {
        "bool": {
          "must": [
            { "match": { "others.key": "0204key" } },
            { "match": { "others.value": "0204value" } }
          ]
        }
      }
    }
  }
}

Currently, the nested search is receiving results well like this way.
However, I want to search for the other fields + nested, is there any way?

        "msgid" : {"type" :"integer"},
        "others" : {
          "type" :"nested",
          "properties" : {
            "key" : {"type" : "text"},
            "value" : {"type" : "text"}
          }
        }

This is an example.

I want nested key and value filed + msgid filed search it together.
If you know how, I would appreciate it if you could let me know. :slight_smile:

1 Like

It is a little bit complex, but I suppose you need one more boolean query containing the nested query.

Like:

{
  "query": {
    "bool":{
      "must":[{
        "range":{
          "msgid": {
            "gte":2
          }
        }
      },{
        "nested": {
          "path": "others",
          "query": {
            "bool": {
              "must": [
                { "match": { "others.key": "0204key" } },
                { "match": { "others.value": "0204value" } }
              ]
            }
          }
        }
      }
      ]
    }
  }
}
1 Like

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