# How to query multiple parameters in a nested field in elasticsearch

**URL:** <https://discuss.elastic.co/t/how-to-query-multiple-parameters-in-a-nested-field-in-elasticsearch/91514>\
**Category:** Elasticsearch\
**Created:** [July 1, 2017, 12:26pm UTC](https://discuss.elastic.co/t/how-to-query-multiple-parameters-in-a-nested-field-in-elasticsearch/91514 "2017-07-01T12:26:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![katsuroo](https://avatars.discourse-cdn.com/v4/letter/k/0ea827/32.png) [@katsuroo](https://discuss.elastic.co/u/katsuroo)\
**Post date:** [July 1, 2017, 12:26pm UTC](https://discuss.elastic.co/t/how-to-query-multiple-parameters-in-a-nested-field-in-elasticsearch/91514/1 "2017-07-01T12:26:45Z")

</div>

I'm trying to search for keyword and then add nested queries for amenities which is a nested field of an array of objects.

With the query below I am able to search when I'm only matching one amenity id but when I have more than one it doesn't return anything.

Anyone have an idea what is wrong with my query ?

```
{
  "sort": [
    {
      "_score": {
        "order": "desc"
      }
    },
    {
      "_geo_distance": {
        "geolocation": [
          100,
          10
        ],
        "order": "asc",
        "unit": "m",
        "mode": "min",
        "distance_type": "sloppy_arc"
      }
    }
  ],
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "fields": [
              "name^2",
              "city",
              "state",
              "zip"
            ],
            "fuzziness": 5,
            "query": "complete"
          }
        },
        {
          "nested": {
            "path": "amenities",
            "query": {
              "bool": {
                "must": [
                  {
                    "term": {
                      "amenities.id": "1"
                    }
                  },
                  {
                    "term": {
                      "amenities.id": "2"
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}
```

---

<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:** [July 29, 2017, 12:27pm UTC](https://discuss.elastic.co/t/how-to-query-multiple-parameters-in-a-nested-field-in-elasticsearch/91514/2 "2017-07-29T12:27:04Z")

</div>

Closed on July 29, 2017, 12:27pm UTC

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