如何组合多匹配查询? [英] how to combine multi match queries?

查看:88
本文介绍了如何组合多匹配查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目的是结合2个多匹配查询,如下所示。我想要MPN或SKU字段必须匹配每个关键字。所以关键字hp和301都必须存在于MPN或SKU中。
或者Name或Name.raw应该有一个关键字hp或301。
精确匹配,MPN / SKU应该具有更高的分数。
我写下如下查询,但它不返回任何结果,虽然有文件有这些条件。
我的问题是,

My purpose is to combine 2 multi match queries as below. I want MPN or SKU fields must match for each keyword. So keywords "hp" and "301" both must be exist either in MPN or SKU. or either Name or Name.raw should have one of the keyword either "hp" or "301". exact match which are MPN/SKU should have higher score. I wrote query as below but it doesnt return any results although there are documents having these conditions. my questions are,

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.

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

I appreciate also any query suggestion for my purpose.

   "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"
                         ]
                }}
             ]
          }
       }


推荐答案

我假设这个问题与这个问题有关。 如何做&&和||在NEST中构建查询的工作?

I am assuming that problem is something related to this question here. How do && and || work constructing queries in NEST?

如果我理解正确,必须和应用的组合应该作为一个助推器,如下面

If I understand correctly, a combination of must and should are acting as must with should as a booster as he says below




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

这是因为一旦布尔查询具有一个必须条款,应该开始作为一个提升因子。所以在

This is because as soon as a boolean query has a must clause the should start acting as a boosting factor. So in the


以前你可以得到的结果只包含term1这是
显然不是你想要的严格布尔值

previous you could get back results that ONLY contain term1 this is clearly not what you want in the strict boolean sense of the input.

因此,我将查询更改为2个应用程序查询,其中一个具有AND运算符。所以这个行为就像MUST一样,因为它会强制所有搜索关键字都应该在字段中找到。

Therefore I changed my query into 2 should queries with one of them having "AND" operator. So this one will behave like MUST as it will force all search keywords should be found in fields.

"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"
                         ]
                }
                }
             ]

          }
       }

这篇关于如何组合多匹配查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆