ElasticSearch 将必须匹配与多重匹配相结合



我一直在尝试将MUST-MATCH与MULTI-MATCH结合起来,但无法让它工作。基本上我想要这些必须的条件:

 "must": [{ "match": { "city": $city } },
          { "match": { "is_displayed": 1 } },
          { "match": { "status": "active" } }]

我想要这些匹配:

            "multi_match": {
                "query": $query,
                "type": $selectedType,
                "fields": fieldArray,
            }

其中$query是文本框值$selectedType是多重匹配查询类型之一,fieldArray 是要搜索的字段。例如,当文本框值为"hello world"且 fieldArray 为 ['title', 'cuisine'] 时,"hello"和/或"world"必须与其中一个或所有指定字段匹配。任何见解和建议都值得赞赏。

我想在

块中添加另一个子句must可以满足需要。

{
 "query": {
  "bool": {
     "must": [
        {
           "match": {
              "city": "$city"
           }
        },
        {
           "match": {
              "is_displayed": 1
           }
        },
        {
           "match": {
              "status": "active"
           }
        },
         "query_string": {
          "fields": fieldArray,
          "query": "*$query*"
         }
        }
       ]
     }
    }
   }

最新更新