Mixing a bool request and multi match / function

I am currently making a request consisting of several matches and functions. The important JSON bit is as follows:

"function_score":{ "query":{ "query_string":{ "query":"some query", "fields":["id","name","strippedDescription","colourSearch","sizeSearch"] } } } 

However, I also want to include results that do not necessarily correspond to the query, but have a specific numerical value greater than 0. I think the bool query will do this, but I don’t know how to use the bool query with the function evaluation query.

I understand that a multi-user request is simply an abbreviation for a bool request, and I could extend the request for a multi-user response to its bool counter, however I do not know then how I would make a function count within this.

Any ideas? By the way, I'm on version 1.1.0.

+7
elasticsearch
source share
1 answer

I thought! I missed the fact that you can embed multi-user queries in bool queries! My final decision is as follows:

 { "query":{ "function_score":{ "query":{ "bool":{ "should": [ { "range": { "allBoost": { "gt": 0 } } },{ "multi_match":{ "query":"some search query", "fields":[ "id", "name", "description", "category" ] } } ] } }, "functions":[ { "filter":{ "range": { "allBoost": { "gt": 0 } } }, "script_score":{ "script":"doc['allBoost'].value" } }, { "filter":{ "range": { "allBoost": { "lte": 0 } } }, "script_score":{ "script":"_score" } } ], "boost_mode": "replace" } } } 
+15
source share

All Articles