php - How to use an Elasticsearch gauss function with min value but no max value, but still get results below min with reduced score? -
im trying create pretty complex query in elasticsearch , have run little problem. can shed light...
i have price value can defined minimum value and/or maximum value, or neither. when min and max defined easy use gauss
function results between min , max score of 1, , decreasing score outside of defined range...
"gauss": { "price_amount": { "origin": 150000, "offset": 50000, "scale": 10000 } }
however, when only min or max defined little trickier.
so example, user defines price range: 100,000 - no max
how construct elasticsearch query in order give consistent score above 100,000, pick documents price below 100,000, penalised score (like when using gauss
function within function_score
query)?
ive thought of filtering results price first (before using gauss
function) if set gte
range query value min (100,000), exclude below 100,000. reduce value assign gte
query capture documents below 100,000, maybe setting 75,000, doesn't feel right...
also, using gauss function reduce score price increases, after offset, isnt need. want consistent score above min (in example), , decaying score below 100,000.
any guidance appreciated.
thanks lee
since posting figured out answer. posting incase comes across this...
the function inside function_score query influences score of documents, , can control documents effect function using filter alongside function.
so solution problem filter follows:
"query": { "function_score": { "min_score": 1e-12, "functions": [ { ... }, { "filter": { "range": { "price_amount": { "lte": 100000 } } }, "gauss": { "price_amount": { "origin": 100000, "offset": 0, "scale": 5000 } } } ], "query": { "constant_score": { "filter": { "bool": { "must": [ [ ... ] ] } } } } } }
this uses gauss bell curve , reduces score of documents price less 100,000. offset 0 score begins decay straight away below minimum value defined user, in example.
Comments
Post a Comment