Elasticsearch - How to boost score by the results of an aggregation? -
my use case follows: execute search against products , boost score salesrank relative other documents in results. top 10% sellers should boosted factor of 1.5 , top 25-10% should boosted factor of 1.25. percentiles calculated on results of query, not entire data set. feature being used on-the-fly instant results user types, single character queries still return results.
so example, if search "widget" , 100 results, top 10 sellers returned boosted 1.5 , top 10-25 boosted 1.25.
i thought of using percentiles aggregation feature calculate 75th , 90th percentiles of result set.
post /catalog/product/_search?_source_include=name,salesrank { "query": { "match_phrase_prefix": { "name": "n" } }, "aggs": { "sales_rank_percentiles": { "percentiles": { "field" : "salesrank", "percents" : [75, 90] } } } }
this gets me following:
{ "hits": { "total": 142, "max_score": 1.6653868, "hits": [ { "_score": 1.6653868, "_source": { "name": "nylon", "salesrank": 46 } }, { "_score": 1.6643861, "_source": { "name": "neon", "salesrank": 358 } }, ..... <snip> ..... ] }, "aggregations": { "sales_rank_percentiles": { "values": { "75.0": 83.25, "90.0": 304 } } } }
so great, gives me results , percentiles. boost "neon" above "nylon" because it's top 10% seller in results (note: in our system, salesrank value descending in precedence, higher value = more sales). text relevancy low since 1 character supplied, sales rank should have big effect.
it seems function core query used here, of examples in documentation uses doc[] use values document. there aren't using other information top-level of response, e.g. "aggs" {}. boost document if sales rank falls within 100-90th , 89th-75th percentiles, 1.5 , 1.25 respectively.
is elasticsearch supports or going have roll own custom script or plugin? or try different approach entirely? preference pre-calculate percentiles, index them, , constant score boost, stakeholder prefers run-time calculation.
i'm using elasticsearch 1.2.0.
what if keep sellers parent document , periodically updates stars (and boosting factor), say, via worker. match products using has_parent
query, , use combination of score mode, custom score query match top products top sellers?
Comments
Post a Comment