【问题标题】:ElasticSearch combine must-match with multi-matchElasticSearch 结合了必须匹配和多重匹配
【发布时间】:2017-05-15 16:44:04
【问题描述】:

我一直在尝试将 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'] 时,“hello”和/或“world”必须匹配任一或所有指定字段。感谢您提供任何见解和建议。

【问题讨论】:

    标签: elasticsearch match


    【解决方案1】:

    我猜想在 must 块中添加另一个子句就可以了。

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

    【讨论】:

    • 我试过了,但只有phrase_prefix返回了结果。其他多重匹配查询类型返回空结果集。
    • phrase_prefix 查询在哪里??
    • 好的,我知道了。 The other multi-match query types returned empty result set .. 这是什么意思?一个查询只会得到一个结果。以上查询将在所有子句中应用AND 操作。
    • 我试图使用部分字符串匹配。我预计 $query ('i') 将返回在任何指定字段 $fieldArray 中具有 'i' 的结果。我怎么可能做到这一点?谢谢!
    猜你喜欢
    • 2022-12-10
    • 1970-01-01
    • 2017-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-09
    相关资源
    最近更新 更多