简体   繁体   中英

How to value exact match higher than term frequency in elasticsearch?

I have an index that has several title fields.

main_title, sub_titles, preferred_titles etc.

These texts fields also have a suggest field each where I run a custom analyzer that uses edge-n-gram tokenizer so we can search as we type.

I would like to value exact match over term frequency. And exact match in main_title is worth more than exact match in preferred_titles.

Anyone know how I can achieve this? Thanks in advance.

I have tried a bool_query with multi_match_query in the must clause. The multi_match is crossfields with no fields attached with the operator 'and'.

I have both the text fields and the suggest fields in the should cluase. Each text field is in a match_query with a boost and the operator 'and'. Each suggest field is in a match_phrase_query with a boost and the operator 'and'. The issue is that several boosts are added on top of the scores and I end up with very inflated scores.

You can use rescore .

Rescoring can help to improve precision by reordering just the top (eg 100 - 500) documents returned by the query and post_filter phases, using a secondary (usually more costly) algorithm, instead of applying the costly algorithm to all documents in the index.

An example:

{
  "query": {
    ... some query
  },
  "from" : 0,
  "size" : 50,
  "rescore" : {
      "score_normalizer" : {
        "normalizer_type" : "min_max",
        "min_score" : 1,
        "max_score" : 10
      }
   }
}

Reference: https://github.com/bkatwal/elasticsearch-score-normalizer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM