JoséMi
JoséMi

Reputation: 11952

Elasticsearch boost but only one occurrence of term per field

I'm currently sending the following query to ElasticSearch:

{
    "size": 100,
    "query": {
        "function_score": {
            "query": {
                "simple_query_string": {
                    "query": "term1",
                    "fields": ["field1^10", "field2^5"]
                }
            }]
        }
    }
}

Now imagine I have two documents.

What I get: Elastic returns Document2 above Document1

What I want: Document1 above Document2.

To achieve this, Elastic should not multiply the number of occurrences of "term1" just that it "appears". What should I do to my query?

Upvotes: 3

Views: 1636

Answers (1)

JoséMi
JoséMi

Reputation: 11952

There seems to be two kinds of options to force Elastic not give more weight based on number of occurrences of a term.

The first one is to map the fields to disable term frequency (TF): https://www.elastic.co/guide/en/elasticsearch/guide/current/scoring-theory.html#tfidf

The second one is to use the Constant Score Query: https://www.elastic.co/guide/en/elasticsearch/guide/current/ignoring-tfidf.html

Upvotes: 4

Related Questions