Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boosting search in specific fields and sorting by rank

I have the following query:

{
    "sort": [
        {"actual_rank" : "desc"}
    ],
    "query": {
        "multi_match" : {
            "query" : term,
            "fields" : [ "title^3" , "category^5" , "entities.name^5"]
        }
    }
}

The problem with this query is that the sorting by rank makes the specified fields boosting pretty irrelevant(a best ranked item in which the term doesn't appear in the specified fields will be higher placed than a worst ranked item in which the term appears).

I'd like to decrease the importance of the sorting to get better results.

like image 319
Rod0n Avatar asked Aug 29 '13 17:08

Rod0n


People also ask

How does Elasticsearch sorting work?

Elasticsearch comes with a good default out of the box. It sorts the results by relevance to the search query term, most relevant first. Elasticsearch measures the relevance score as a floating-point number called _score, and orders results in the descending order of their _score values.

How do I sort in Elasticsearch query?

Sort mode optioneditPick the highest value. Use the sum of all values as sort value. Only applicable for number based array fields. Use the average of all values as sort value.

What is _score in Elasticsearch?

The _score in Elasticsearch is a way of determining how relevant a match is to the query. The default scoring function used by Elasticsearch is actually the default built in to Lucene which is what Elasticsearch runs under the hood.


1 Answers

Actually, according to the sorting docs (http://www.elasticsearch.org/guide/reference/api/search/sort/), you need to enable the track_scores setting if you want scores to be calculated at all when sorting on a field.

However, I'm guessing you want to do some custom scoring (see http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query/ and/or http://www.elasticsearch.org/guide/reference/query-dsl/custom-filters-score-query/). Examples of those are excellent in this blog post (http://jontai.me/blog/2013/01/advanced-scoring-in-elasticsearch/)

I'd post code, but I think the blog post provides a thorough view.

like image 100
James Addison Avatar answered Nov 26 '22 21:11

James Addison