How to avoid multiple word matches without changing index_option

I have a query running on my index as follows:

GET /index/type/_search?search_type=dfs_query_then_fetch
{
"query": {
"bool": {
"must": [{"match": { "field": {"query":"search_value","boost":2}}]
}
}
}

Every time the search_value is encountered, it gets boosted. I would like to to be boosted only once if encountered, or twice as per requirements. How can I avoid multiple boost given to matches?

The documentation says that if you change index_option to docs, it will disable term frequencies. However, i cannot use match_phrase option then.
Thanks a lot for your opinion and ideas!

The boost is applied to the score of the match query so it's only applied once per matching document.
Though the score of the match query takes the frequency of the "search_value" into account so the score for a document with multiple occurrences of this term will be different than a document with a single occurrence.
If you want to ignore the frequencies of the terms you can use the boolean similarity:
https://www.elastic.co/guide/en/elasticsearch/reference/master/similarity.html

Thank you so much for your response. I changed my mapping to this:

PUT index_name
{
"mappings" : {
"type" : {
"properties" : {
"field_name":{
"type": "text",
"similarity": "boolean"
}
}
}
}
}

However, I am getting this error:

{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "Unknown Similarity type [boolean] for field [skills]"
}
],
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [candidate]: Unknown Similarity type [boolean] for field [skills]",
"caused_by": {
"type": "mapper_parsing_exception",
"reason": "Unknown Similarity type [boolean] for field [skills]"
}
},
"status": 400
}

Any help with this?

The boolean similarity has been added in 5.4 so I guess you're using an older version ?

I am using version 5.3. I guess that's why the issue is occurring.

Yes, you should upgrade to 5.4 to be able to use this new similarity

1 Like

Will do. Thanks!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.