Nariman Esmaiely Fard
Nariman Esmaiely Fard

Reputation: 615

Give more score to documents that contains all query terms

I have a problem with scoring in elasticsearch. When user enter a query that contains 3 terms, sometimes a document that has two words a lot, outscores a document that contains all three words. for example if user enters "elasticsearch query tutorial", I want documents that contains all these words score higher than a document with a lot of "tutorial" and "elasticsearch" terms in it.

PS: I am using minimum should match and shingls in my query. also they made ranking a lot better, they did not solve this problem completely. I need something like query coordination in lucene's practical scoring function. is there anything like that in elastic with BM-25?

Upvotes: 0

Views: 165

Answers (1)

Mysterion
Mysterion

Reputation: 9320

One of the possible solutions could be using function score:

{
    "query": {
        "function_score": {
          "query": { "match_all": {} },
          "functions": [
              {
                  "filter": { "match": { "title": "elasticserch" } },
                  "weight": 1
              },
              {
                  "filter": { "match": { "title": "tutorial" } },
                  "weight": 1
              }
          ],
          "score_mode": "sum"
        }
    }
}

In this case, you would have clearly a better position for documents with more matches. However, this would completely ignore TF-IDF or any other parameters.

Upvotes: 1

Related Questions