【问题标题】:how to combine multi match queries?如何组合多匹配查询?
【发布时间】:2016-08-11 22:33:38
【问题描述】:

我的目的是组合 2 个多重匹配查询,如下所示。我希望 MPN 或 SKU 字段必须与每个关键字匹配。因此关键字“hp”和“301”都必须存在于 MPN 或 SKU 中。 或者 Name 或 Name.raw 应该具有关键字“hp”或“301”之一。 MPN/SKU 的完全匹配应该有更高的分数。 我编写了如下查询,但尽管有文档具有这些条件,但它没有返回任何结果。 我的问题是,

1) Does must query require keyword to be found in both SKU and MPN
for the multi_match query?

2) Combination of must and should is AND or OR? it looks like AND
for me as it doesn't return any result. if it is AND, how to make it
as OR? I cant find any operator on bool. I tried to wrap in another
should query but it didnt help.

我也感谢任何针对我的目的的查询建议。

   "from": 0,
       "size": 10,
       "explain": true,
       "query": {
          "bool": {
             "must": [
                {
                   "multi_match": {
                      "type": "best_fields",
                      "query": "hp 301",
                      "fields": [                       
                         "MPN^9",
                         "SKU^8"             
                      ],
              "operator": "and"
                   }
                }
             ],
             "should": [
                {"multi_match": {
                      "type": "best_fields",
                   "query": "hp 301",
                   "fields": [
                        "Name.raw2^7.5",
                         "Name^7"
                         ]
                }}
             ]
          }
       }

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    我假设问题与这里的这个问题有关。 How do && and || work constructing queries in NEST?

    如果我理解正确,must 和 should 的组合就像他所说的 must 和 should 作为助推器一样

    bool
    >     must 
    >         term1
    >     should
    >         term2
    >         term3
    >         term4 
    

    这是因为一旦布尔查询具有 must 子句,就应该开始充当助推因素。所以在

    previous 您可以返回仅包含 term1 的结果,这是 在输入的严格布尔意义上,显然不是您想要的。

    因此,我将查询更改为 2 个应该查询,其中一个具有“AND”运算符。因此,此选项的行为类似于 MUST,因为它将强制所有搜索关键字都应在字段中找到。

    "from": 0,
           "size": 10,
           "explain": true,
           "query": {
              "bool": {
                 "should": [
                    {
                       "multi_match": {
                          "type": "best_fields",
                          "query": "hp 301",
                          "fields": [                       
                             "MPN^9",
                             "SKU^8"             
                          ],
                  "operator": "and"
                       }
                    }               ,
                    {
                    "multi_match": {
                          "type": "best_fields",
                       "query": "hp 301",
                       "fields": [
                            "Name.raw2^7.5",
                             "Name^7"
                             ]
                    }
                    }
                 ]
    
              }
           }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-09
      • 1970-01-01
      • 2020-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-06
      • 1970-01-01
      相关资源
      最近更新 更多