# Multiple query with nested

**URL:** <https://discuss.elastic.co/t/multiple-query-with-nested/286020>\
**Category:** Elasticsearch\
**Created:** [October 6, 2021, 11:46am UTC](https://discuss.elastic.co/t/multiple-query-with-nested/286020 "2021-10-06T11:46:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![elastic\_dev](https://avatars.discourse-cdn.com/v4/letter/e/cab0a1/32.png) [@elastic\_dev](https://discuss.elastic.co/u/elastic_dev)\
**Post date:** [October 6, 2021, 11:46am UTC](https://discuss.elastic.co/t/multiple-query-with-nested/286020/1 "2021-10-06T11:46:19Z")

</div>

Hi Below is my data.

```auto
{
  "took" : 5,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "resturant",
        "_type" : "_doc",
        "_id" : "135569",
        "_score" : 1.0,
        "_source" : {
          "id" : "135569",
          "name" : "pizza hut",
          "location" : [
            -118.396294,
            33.8787
          ],
          "categories" : [
            "Fast Food",
            "FamilyStyle",
            "Chinese"
          ],
          "menu" : [
            {
              "name" : "Build Your Own Plate - 1 Full Side",
              "id" : 6226,
              "price" : 10.05
            },
            {
              "name" : "Build Your Own Bigger Plate - 1 Full Side",
              "id" : 6228,
              "price" : 11.85
            },
            {
              "name" : "Build Your Own Bowl - 1 Full Side",
              "id" : 6230,
              "price" : 8.25
            },
            {
              "name" : "Family Feast - 2 Full Sides",
              "id" : 6232,
              "price" : 44.7
            },
            {
              "name" : "Chicken Egg Roll",
              "id" : 6234,
              "price" : 2.35
            },
            {
              "name" : "Side Fried Rice",
              "id" : 6238,
              "price" : 4.15
            },
            {
              "name" : "Veggie SpringRoll",
              "id" : 6247,
              "price" : 2.35
            },
            {
              "name" : "Dasani Bottle",
              "id" : 6261,
              "price" : 2.3
            }
          ],
          "facility" : "take_out",
          "city" : "Manhattan Beach",
          "state" : "CA",
          "zip" : "90266",
          "rating" : 4.5
        }
      },
      {
        "_index" : "resturant",
        "_type" : "_doc",
        "_id" : "18220",
        "_score" : 1.0,
        "_source" : {
          "id" : 18220,
          "name" : "Shade Hotel Manhattan Beach",
          "location" : [
            -118.408875,
            33.886745
          ],
          "categories" : [
            "Contemporary Casual",
            "Family Style",
            "Brunch / Breakfast",
            "American"
          ],
          "menu" : [
            {
              "name" : "Chicken and Waffle Bites Breakfast Plate",
              "id" : 6264,
              "price" : 17
            },
            {
              "name" : "Avocado Toast",
              "id" : 6267,
              "price" : 19
            },
            {
              "name" : "Breakfast Pizza",
              "id" : 6270,
              "price" : 19
            },
            {
              "name" : "Crispy Calamari Lunch",
              "id" : 6274,
              "price" : 17
            },
            {
              "name" : "Roasted Squash Veggie Bowl Lunch",
              "id" : 6279,
              "price" : 19
            },
            {
              "name" : "Beyond Burger Lunch",
              "id" : 6284,
              "price" : 21
            },
            {
              "name" : "Spicy Hawaiian Pizza Lunch",
              "id" : 6291,
              "price" : 20
            },
            {
              "name" : "The Burrito",
              "id" : 6292,
              "price" : 18
            },
            {
              "name" : "Buttermilk Pancakes",
              "id" : 6294,
              "price" : 15
            },
            {
              "name" : "Truffle Fries",
              "id" : 6301,
              "price" : 11
            },
            {
              "name" : "Roasted Squash Veggie Bowl",
              "id" : 6306,
              "price" : 19
            },
            {
              "name" : "Fried Jidori Chicken Sandwich",
              "id" : 6310,
              "price" : 19
            },
            {
              "name" : "Spicy Hawaiian Pizza",
              "id" : 6315,
              "price" : 20
            },
            {
              "name" : "Carnitas Street Tacos",
              "id" : 6322,
              "price" : 14
            },
            {
              "name" : "Roasted Squash Veggie Bowl Dinner",
              "id" : 6327,
              "price" : 19
            },
            {
              "name" : "Spicy Hawaiian Pizza Dinner",
              "id" : 6332,
              "price" : 20
            },
            {
              "name" : "Prime Rib DipDinner",
              "id" : 6342,
              "price" : 21
            }
          ],
          "facility" : [
            "indoor_dining",
            "outdoor_sitting",
            "take_out"
          ],
          "city" : "ManhattanBeach",
          "state" : "CA",
          "zip" : "90266",
          "rating" : 5
        }
      }
    ]
  }
}

```

Now I want to search **name** and **menu** with word **pizza**.

I am trying to search with the below search query but I give zero results.

```auto
curl -XGET 192.168.10.107:9200/resturant/_search?pretty -d '{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "name": "pizza"
          }
        },
        {
          "nested": {
            "path": "menu",
            "query": {
              "bool": {
                "must": [
                { "match": { "menu.name": "pizza" } }
                ]
              }
            }
          }
        }
      ]
    }
  }
}'

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 6, 2021, 12:22pm UTC](https://discuss.elastic.co/t/multiple-query-with-nested/286020/2 "2021-10-06T12:22:30Z")

</div>

We don't see the mapping here.

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can **copy and paste in Kibana dev console** , click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![elastic\_dev](https://avatars.discourse-cdn.com/v4/letter/e/cab0a1/32.png) [@elastic\_dev](https://discuss.elastic.co/u/elastic_dev)\
**Post date:** [October 6, 2021, 2:03pm UTC](https://discuss.elastic.co/t/multiple-query-with-nested/286020/3 "2021-10-06T14:03:51Z")

</div>

Hi below is the mapping and whole information about what I did so far.

```auto
 curl -XPUT localhost:9200/resturant -d'
{
"mappings": {
"properties": {
 "name": {
 "type": "text"
 },
 "location": {
"type": "geo_point"
 },
 "menu": {
 "type": "nested"
},
"city":{
"type":"keyword"
}
}
}
}'

```

1. Added data in bulk from json file. Below is the command I used

```auto
curl -XPUT localhost:9200/_bulk?pretty --data-binary @resturant.json

```

1. Here is the data.

```auto
{ "create" : { "_index" : "resturant", "_id" : "135569" } }
{ "id": "135569", "name" : "pizza hut","location":[-118.396294,33.8787],"categories":["Fast Food","FamilyStyle","Chinese"],"menu":[{"name":"Build Your Own Plate - 1 Full Side","id":6226,"price":10.05},{"name":"Build Your Own Bigger Plate - 1 Full Side","id":6228,"price":11.85},{"name":"Build Your Own Bowl - 1 Full Side","id":6230,"price":8.25},{"name":"Family Feast - 2 Full Sides","id":6232,"price":44.7},{"name":"Chicken Egg Roll","id":6234,"price":2.35},{"name":"Side Fried Rice","id":6238,"price":4.15},{"name":"Veggie SpringRoll","id":6247,"price":2.35},{"name":"Dasani Bottle","id":6261,"price":2.3}],"facility":"take_out","city":"Manhattan Beach","state":"CA","zip":"90266","rating":4.5}
{ "create" : { "_index" : "resturant", "_id" : "18220" } }
{"id":18220,"name":"Shade Hotel Manhattan Beach","location":[-118.408875,33.886745],"categories":["Contemporary Casual","Family Style","Brunch \/ Breakfast","American"],"menu":[{"name":"Chicken and Waffle Bites Breakfast Plate","id":6264,"price":17},{"name":"Avocado Toast","id":6267,"price":19},{"name":"Breakfast Pizza","id":6270,"price":19},{"name":"Crispy Calamari Lunch","id":6274,"price":17},{"name":"Roasted Squash Veggie Bowl Lunch","id":6279,"price":19},{"name":"Beyond Burger Lunch","id":6284,"price":21},{"name":"Spicy Hawaiian Pizza Lunch","id":6291,"price":20},{"name":"The Burrito","id":6292,"price":18},{"name":"Buttermilk Pancakes","id":6294,"price":15},{"name":"Truffle Fries","id":6301,"price":11},{"name":"Roasted Squash Veggie Bowl","id":6306,"price":19},{"name":"Fried Jidori Chicken Sandwich","id":6310,"price":19},{"name":"Spicy Hawaiian Pizza","id":6315,"price":20},{"name":"Carnitas Street Tacos","id":6322,"price":14},{"name":"Roasted Squash Veggie Bowl Dinner","id":6327,"price":19},{"name":"Spicy Hawaiian Pizza Dinner","id":6332,"price":20},{"name":"Prime Rib DipDinner","id":6342,"price":21}],"facility":["indoor_dining","outdoor_sitting","take_out"],"city":"ManhattanBeach","state":"CA","zip":"90266","rating":5}

```

1. Now I want to search **name** and **menu** with word **pizza**.

I am trying to search with the below search query but I give zero results.

1. Below is the search I used.

```auto
curl -XGET 192.168.10.107:9200/resturant/_search?pretty -d '{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "name": "pizza"
          }
        },
        {
          "nested": {
            "path": "menu",
            "query": {
              "bool": {
                "must": [
                { "match": { "menu.name": "pizza" } }
                ]
              }
            }
          }
        }
      ]
    }
  }
}'

```

---

<div class="post-metadata">

**Author:** ![elastic\_dev](https://avatars.discourse-cdn.com/v4/letter/e/cab0a1/32.png) [@elastic\_dev](https://discuss.elastic.co/u/elastic_dev)\
**Post date:** [October 6, 2021, 2:10pm UTC](https://discuss.elastic.co/t/multiple-query-with-nested/286020/4 "2021-10-06T14:10:50Z")

</div>

Below is the output I am getting

```auto
{
  "took" : 20,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : []
  }
}

```

---

<div class="post-metadata">

**Author:** ![soumilshah1995](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/soumilshah1995/32/62201_2.png) [@soumilshah1995](https://discuss.elastic.co/u/soumilshah1995)\
**Post date:** [October 6, 2021, 3:03pm UTC](https://discuss.elastic.co/t/multiple-query-with-nested/286020/5 "2021-10-06T15:03:55Z")

</div>

Hi follow this  
this will help you

@elastic_dev

[![](https://us1.discourse-cdn.com/elastic/original/3X/d/4/d4ea8c5e831878dd636c960d34ee53d92737dbf3.jpeg "Elastic Search Queries : Searching in Nested Array of Documents and Filtering Q by Keval Jain") ](https://www.youtube.com/watch?v=HpNYqIPvy7c)

---

<div class="post-metadata">

**Author:** ![elastic\_dev](https://avatars.discourse-cdn.com/v4/letter/e/cab0a1/32.png) [@elastic\_dev](https://discuss.elastic.co/u/elastic_dev)\
**Post date:** [October 7, 2021, 2:24pm UTC](https://discuss.elastic.co/t/multiple-query-with-nested/286020/6 "2021-10-07T14:24:26Z")

</div>

@ [soumilshah1995](https://discuss.elastic.co/u/soumilshah1995)  
Hi,

Thank you so much, your video helped. This is what I was looking for.

---

<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:** [November 4, 2021, 2:24pm UTC](https://discuss.elastic.co/t/multiple-query-with-nested/286020/7 "2021-11-04T14:24:59Z")

</div>

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