WARNING: The 2.x versions of Elasticsearch have passed their EOL dates. If you are running a 2.x version, we strongly advise you to upgrade.
This documentation is no longer maintained and may be removed. For the latest information, see the current Elasticsearch documentation.
Query-Time Boostingedit
In Prioritizing Clauses, we explained how you could use the boost
parameter at search time to give one query clause more importance than
another. For instance:
GET /_search { "query": { "bool": { "should": [ { "match": { "title": { "query": "quick brown fox", "boost": 2 } } }, { "match": { "content": "quick brown fox" } } ] } } }
The |
|
A query clause without a |
Query-time boosting is the main tool that you can use to tune relevance. Any
type of query accepts a boost
parameter. Setting a boost
of 2
doesn’t
simply double the final _score
; the actual boost value that is applied
goes through normalization and some internal optimization. However, it does
imply that a clause with a boost of 2
is twice as important as a clause with
a boost of 1
.
Practically, there is no simple formula for deciding on the “correct” boost
value for a particular query clause. It’s a matter of try-it-and-see.
Remember that boost
is just one of the factors involved in the relevance
score; it has to compete with the other factors. For instance, in the preceding
example, the title
field will probably already have a “natural” boost over
the content
field thanks to the field-length norm (titles
are usually shorter than the related content), so don’t blindly boost fields
just because you think they should be boosted. Apply a boost and check the
results. Change the boost and check again.
Boosting an Indexedit
When searching across multiple indices, you can boost an entire index over
the others with the indices_boost
parameter. This could be used, as in the
next example, to give more weight to documents from a more recent index:
t.getBoost()edit
These boost values are represented in the Lucene’s Practical Scoring Function by
the t.getBoost()
element. Boosts are not applied at the level that they
appear in the query DSL. Instead, any boost values are combined and passed
down to the individual terms. The t.getBoost()
method returns any boost
value applied to the term itself or to any of the queries higher up the chain.
In fact, reading the explain
output is a little more complex
than that. You won’t see the boost
value or t.getBoost()
mentioned in the
explanation
at all. Instead, the boost is rolled into the
queryNorm
that is applied to a particular term. Although we said that
the queryNorm
is the same for every term, you will see that the queryNorm
for a boosted term is higher than the queryNorm
for an unboosted term.
- Elasticsearch - The Definitive Guide:
- Foreword
- Preface
- Getting Started
- You Know, for Search…
- Installing and Running Elasticsearch
- Talking to Elasticsearch
- Document Oriented
- Finding Your Feet
- Indexing Employee Documents
- Retrieving a Document
- Search Lite
- Search with Query DSL
- More-Complicated Searches
- Full-Text Search
- Phrase Search
- Highlighting Our Searches
- Analytics
- Tutorial Conclusion
- Distributed Nature
- Next Steps
- Life Inside a Cluster
- Data In, Data Out
- What Is a Document?
- Document Metadata
- Indexing a Document
- Retrieving a Document
- Checking Whether a Document Exists
- Updating a Whole Document
- Creating a New Document
- Deleting a Document
- Dealing with Conflicts
- Optimistic Concurrency Control
- Partial Updates to Documents
- Retrieving Multiple Documents
- Cheaper in Bulk
- Distributed Document Store
- Searching—The Basic Tools
- Mapping and Analysis
- Full-Body Search
- Sorting and Relevance
- Distributed Search Execution
- Index Management
- Inside a Shard
- You Know, for Search…
- Search in Depth
- Structured Search
- Full-Text Search
- Multifield Search
- Proximity Matching
- Partial Matching
- Controlling Relevance
- Theory Behind Relevance Scoring
- Lucene’s Practical Scoring Function
- Query-Time Boosting
- Manipulating Relevance with Query Structure
- Not Quite Not
- Ignoring TF/IDF
- function_score Query
- Boosting by Popularity
- Boosting Filtered Subsets
- Random Scoring
- The Closer, The Better
- Understanding the price Clause
- Scoring with Scripts
- Pluggable Similarity Algorithms
- Changing Similarities
- Relevance Tuning Is the Last 10%
- Dealing with Human Language
- Aggregations
- Geolocation
- Modeling Your Data
- Administration, Monitoring, and Deployment