# How to nested and other field search

**URL:** <https://discuss.elastic.co/t/how-to-nested-and-other-field-search/296147>\
**Category:** Elasticsearch\
**Created:** [February 3, 2022, 6:12am UTC](https://discuss.elastic.co/t/how-to-nested-and-other-field-search/296147 "2022-02-03T06:12:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sramana235](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@sramana235](https://discuss.elastic.co/u/sramana235)\
**Post date:** [February 3, 2022, 6:12am UTC](https://discuss.elastic.co/t/how-to-nested-and-other-field-search/296147/1 "2022-02-03T06:12:16Z")

</div>

Hello!  
I want to know about the search conditions.

```auto
{
  "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?

```auto
        "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. 🙂

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [February 3, 2022, 7:11am UTC](https://discuss.elastic.co/t/how-to-nested-and-other-field-search/296147/2 "2022-02-03T07:11:59Z")

</div>

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

Like:

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

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 3, 2022, 7:12am UTC](https://discuss.elastic.co/t/how-to-nested-and-other-field-search/296147/3 "2022-03-03T07:12:34Z")

</div>

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