针对嵌套和非嵌套字段的弹性搜索查询

时间:2015-08-03 19:16:00

标签: elasticsearch

我正在索引ES餐厅及其菜肴。餐厅的菜肴是嵌套的,还有几种菜肴。餐厅名称和菜肴(列表也在外面)。结构有点像这样:

String

我正在尝试对它们运行应该(OR)查询,如下所示:

{ 
     "restaurant_name": "Dominos",
     "cuisines": ["Italian", "Continental"],
     "restaurant_dishes": [
          {
              "dish_name": "Margherita"
          },
          {
               "dish_name": "Piri Piri Pizza"
          }
      ]
}

以下是映射:

{
  "query": {

    "bool": { 
              "should": [ 
                          {
                              "term": {"restaurant_name": "Dominos"}
                          },
                          {    
                              "nested": {

                                "path": "restaurant_dishes",
                                "query": {
                                          "match": {
                                            "dish_name": "Dominos"
                                                   }
                                          }
                                       }
                          }
                        ],
             "minimum_number_should_match": 1

    }

  }
}

我希望这会返回列表,因为 { "restaurant": { "_routing": { "required": True, "path": "id" }, "properties": { "restaurant_name": {"type": "string", "index":"analyzed", "analyzer": "standard"},}, "restaurant_dishes": { "type": "nested", "properties": {"dish_name": {"type": "string", "index": "analyzed", "analyzer": "standard"},} 字段匹配。但是它返回一个空列表。我基本上想要实现一个搜索框,在一个查询中搜索"name"

0 个答案:

没有答案