Searching across multiple fields in Elasticsearch is a common requirement in many applications. In this article, we will explore advanced techniques to perform searches by two fields, including multi-match queries, bool queries, and query-time field boosting. These techniques will help you to create more accurate and relevant search results for your users.
Advanced techniques to perform searches by two fields
1. Multi-match query
A multi-match query allows you to search for a single query string across multiple fields. This is useful when you want to find documents that contain the given query string in either of the two fields. Here’s an example of a multi-match query searching for the term “example” in the fields “title” or “description”:
{
"query": {
"multi_match": {
"query": "example",
"fields": ["title", "description"]
}
}
}
2. Bool query
A bool query allows you to combine multiple queries using boolean logic. You can use the “should” clause to search for documents that match the query in either of the two fields. Here’s an example of a bool query searching for the term “example” in the fields “title” and “description”:
{
"query": {
"bool": {
"should": [
{"match": {"title": "example"}},
{"match": {"description": "example"}}
]
}
}
}
3. Query-time field boosting
Sometimes, you may want to give more importance to one field over another during the search. You can achieve this by applying a boost factor to the field at query time. A higher boost value gives more weight to the field, making it more likely to influence the final search score. Here’s an example of a multi-match query with a boost factor applied to the “title” field:
{
"query": {
"multi_match": {
"query": "example",
"fields": ["title^3", "description"]
}
}
}
In this example, the “title” field has a boost factor of 3, making it three times more important than the “description” field in determining the search score.
4. Combining queries with different boost factors
You can also combine multiple queries with different boost factors using a bool query. This allows you to fine-tune the importance of each field in the search results. Here’s an example of a bool query with different boost factors applied to the “title” and “description” fields:
{
"query": {
"bool": {
"should": [
{"match": {"title": {"query": "example", "boost": 3}}},
{"match": {"description": {"query": "example", "boost": 1}}}
]
}
}
}
In this example, the “title” field has a boost factor of 3, while the “description” field has a boost factor of 1.
Conclusion
Searching by two fields in Elasticsearch can be achieved using advanced techniques such as multi-match queries, bool queries, and query-time field boosting. By combining these techniques, you can create more accurate and relevant search results for your users. Experiment with different query combinations and boost factors to find the optimal search configuration for your specific use case.
Ready to try this out on your own? Start a free trial.
Want to get Elastic certified? Find out when the next Elasticsearch Engineer training is running!
Related content

August 22, 2025
Exploring Vertex AI with Elasticsearch
Discover how to integrate Vertex AI with Elasticsearch to create a RAG application. Follow this tutorial to configure a Gemini model and use it in Kibana's Playground.

Evaluating your Elasticsearch LLM applications with Ragas
Assessing the quality of a RAG solution using Ragas metrics and Elasticsearch.

August 20, 2025
Turbocharge your troubleshooting: Building a RAG application for appliance manuals with Elasticsearch
Learn how to build a RAG app using Elasticsearch to effortlessly troubleshoot your home appliance issues.

August 13, 2025
Failure store: see what didn’t make it
Learn about failure store, a new feature in the Elastic Stack that captures and indexes previously lost events.

August 14, 2025
Elasticsearch shards and replicas: A practical guide
Master the concepts of Elasticsearch shards and replicas and learn how to optimize them.