从elasticsearch中的多个嵌套级别字段中搜索

时间:2016-03-04 11:30:40

标签: laravel elasticsearch

我想从多个嵌套级别字段中搜索。查询如。

select * from product where brand='brand1' and category='category1'.

在elasticsearch中我有两个嵌套级别映射一个是类别,另一个是品牌

如果我写了只有品牌或类别,会返回完美的结果,但是如何在以下查询中写两个?

    $params = [
                'index' => 'my_index',
                'type' => 'product',
                'body' =>  [
                "query"=>[
                   "filtered"=>[
                      "filter"=>[
                         "bool"=>[
                            "must"=>[
                               "bool"=>[
                                  "must"=>[
                                     [
                                        "query"=>[
                                           "match"=>[
                                              "brand"=>[
                                                 "query"=>"brand1",
                                                 "type"=>"phrase"
                                              ]
                                           ]
                                        ]
                                     ],
                                     [
                                        "query"=>[
                                           "match"=>[
                                              "category"=>[
                                                 "query"=>"category1",
                                                 "type"=>"phrase"
                                              ]
                                           ]
                                        ]
                                     ]
                                  ]
                               ]
                            ]
                         ]
                      ]
                   ]
                ]
            ]      

       ];

通过以上查询我得到0结果

1 个答案:

答案 0 :(得分:0)

您可以尝试以下查询,它将帮助您获得受尊重的答案:

GET / product / ur_type / _search     {      "来自":0,      "尺寸":200,      "查询":{         "过滤":{             "过滤":{                 " bool":{                     "必须":{                         " bool":{                             "必须":[                                 {                                     "查询":{                                         "匹配":{                                             "品牌":{                                                 "查询":" brand1",                                                 "输入":"短语"                                             }                                         }                                     }                                 },                                 {                                     "查询":{                                         "匹配":{                                             "类别":{                                                 "查询":" category1",                                                 "输入":"短语"                                             }                                         }                                     }                                 }                             ]                         }                     }                 }             }         }       }      }

相关问题