Multiple query with nested

Hi Below is my data.

{
  "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.

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" } }
                ]
              }
            }
          }
        }
      ]
    }
  }
}'

We don't see the mapping here.

Could you provide a full recreation script as described in About the Elasticsearch category. 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.

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

 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
curl -XPUT localhost:9200/_bulk?pretty --data-binary @resturant.json
  1. Here is the data.
{ "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.
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" } }
                ]
              }
            }
          }
        }
      ]
    }
  }
}'

Below is the output I am getting

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

Hi follow this
this will help you

@elastic_dev

@ soumilshah1995
Hi,

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

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