Boosting query
Returns documents matching a positive query while reducing the relevance score of documents that also match a negative query.
You can use the boosting query to demote certain documents without excluding them from the search results.
Example request
resp = client.search(
query={
"boosting": {
"positive": {
"term": {
"text": "apple"
}
},
"negative": {
"term": {
"text": "pie tart fruit crumble tree"
}
},
"negative_boost": 0.5
}
},
)
print(resp) response = client.search(
body: {
query: {
boosting: {
positive: {
term: {
text: 'apple'
}
},
negative: {
term: {
text: 'pie tart fruit crumble tree'
}
},
negative_boost: 0.5
}
}
}
)
puts response const response = await client.search({
query: {
boosting: {
positive: {
term: {
text: "apple",
},
},
negative: {
term: {
text: "pie tart fruit crumble tree",
},
},
negative_boost: 0.5,
},
},
});
console.log(response); GET /_search
{
"query": {
"boosting": {
"positive": {
"term": {
"text": "apple"
}
},
"negative": {
"term": {
"text": "pie tart fruit crumble tree"
}
},
"negative_boost": 0.5
}
}
} Top-level parameters for boosting
-
positive - (Required, query object) Query you wish to run. Any returned documents must match this query.
-
negative -
(Required, query object) Query used to decrease the relevance score of matching documents.
If a returned document matches the
positivequery and this query, theboostingquery calculates the final relevance score for the document as follows:- Take the original relevance score from the
positivequery. - Multiply the score by the
negative_boostvalue.
- Take the original relevance score from the
-
negative_boost - (Required, float) Floating point number between
0and1.0used to decrease the relevance scores of documents matching thenegativequery.
© 2023-2025 Elasticsearch
As of September 2024, Elasticsearch is available under a choice of three licenses: the Server Side Public License (SSPL), the Elastic License, or the AGPLv3 (OSI approved).
Elasticsearch and the Elasticsearch logo are trademarks of Elasticsearch B.V., registered in the U.S. and in other countries.
https://www.elastic.co/guide/en/elasticsearch/reference/8.17/query-dsl-boosting-query.html