How to combine multiple matches?

My goal is to combine two multi-user queries as shown below. I want the MPN or SKU fields to match each keyword. Thus, the keywords ā€œhpā€ and ā€œ301ā€ must exist either in the MPN or in the SKU. or the name Name or Name.raw must have one of the keywords: "hp" or "301". Exact match that MPN / SKU should have a higher score. I wrote a query as shown below, but it does not return any results, although there are documents that have these conditions. my questions:

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 also appreciate any offer request 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" ] }} ] } } 
0
source share
1 answer

I assume the problem is related to this issue. How to do && and || job building queries in NEST?

If I understand correctly, the combination of must and should should act as it should be as a booster, as he says below

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

This is due to the fact that, as soon as a logical request has a prerequisite, it should begin to act as a factor of increase. So in

previous you could return results that ONLY contain term1, this is clearly not what you want in the strict logical sense of the input.

Therefore, I changed my request to 2 questions with one of them with the "AND" operator. Thus, this one will behave as MUST, as it will force all search keywords to be found in the 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" ] } } ] } } 
0
source

Source: https://habr.com/ru/post/973582/


All Articles