ElasticSearch结合必须匹配多重匹配

时间:2017-05-15 07:37:37

标签: elasticsearch match

我一直在努力将MUST-MAT​​CH与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'],或者#34;你好"和/或"世界"必须匹配任一或所有指定的字段。任何见解和建议都表示赞赏。

1 个答案:

答案 0 :(得分:0)

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

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

         "query_string": {
          "fields": fieldArray,
          "query": "*$query*"
         }
        }
       ]
     }
    }
   }
相关问题