如何在弹性搜索中使用多重匹配在单个字段中搜索多个单词

时间:2017-12-01 07:48:47

标签: php elasticsearch

如何在单个字段中搜索多个单词。就像我想搜索"诺基亚充电器" Field' prod_name'拥有="诺基亚6300 Silver On Orange PAYG手机充电器"

下面是我的代码

"query" => [
               "bool" => [
                  "must" => [
                     [
                          "multi_match" => [
                             "fields" => ["prod_name", "prod_seo_name","prod_model","keywords","prod_seo_keywords","prod_sku"],
                              "type" => "phrase",
                             "query" => "nokia charger"

                          ]
                     ],

                  ]
               ]
            ],

            ],

现在我正在尝试下面的代码,它部分工作,我想添加术语。

 "query" => [

                          "multi_match" => [
                             "fields" => ["prod_name", "prod_seo_name","prod_model","keywords","prod_seo_keywords","prod_sku"],
                              "type" => "phrase",
                             "query" => $query,

                              //"operator"=>   "and"
                          ],

            ],

            ],
       ];
      if (isset($prod_cat_type)) {
            $params['body']['query'][] = [
            'term' => ['productCategory' => $prod_cat_type],
            ];
        }

任何帮助将不胜感激。 :)

0 个答案:

没有答案