Elasticsearch - How to increase score based on aggregation results?

My use case is as follows: Search for products and increase the score for its salesRank compared to other documents in the results. The top 10% of sellers should be increased 1.5 times, and the top 25-10% should be increased 1.25 times. Percentages are calculated based on the results of the query, and not over the entire data set. This function is used for instant results on the fly when the user enters data, so single-character queries will return results.

So, for example, if I search for “Widget” and return 100 results, the returned 10 sellers will be increased by 1.5, and the top 10-25 will be increased by 1.25.

I immediately thought about using the percentiles aggregation function to compute the 75th and 90th percentiles of the 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 causes the 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
         }
      }
   }
}

It's so cool that it gives me results and percentiles. But I would like to increase the “neon” above the “nylon”, because it is the best seller of 10% in the results (note: in our system, the SalesRank value is lowered by priority, higher value = more sales). The relevance of the text is very low since only one character was provided, so a sales rating should have a big effect.

, , doc [] . , , "aggs" {}. , 100-90- 89--75- , 1,5 1,25.

-, Elasticsearch, script ? ? , , , .

Elasticsearch 1.2.0.

+4
1

, ( ), , - . has_parent , - ?

+1

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


All Articles