Elasticsearch search by two fields

Explore techniques for searching by two fields, including multi-match queries, bool queries, and query-time field boosting.

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

Testing Elasticsearch. It just got simpler.

March 19, 2026

Testing Elasticsearch. It just got simpler.

Explaining how Elasticsearch integration tests have become simpler thanks to improvements in Elasticsearch 9.x, the modern Java client, and Testcontainers 2.x.

Elasticsearch Serverless pricing demystified: VCUs and ECUs explained

December 19, 2025

Elasticsearch Serverless pricing demystified: VCUs and ECUs explained

Learn how Elasticsearch Serverless pricing works for Elastic’s fully-managed deployment offering. We explain VCUs (Search, Ingest, ML) and ECUs, detailing how consumption is based on actual allocated resources, workload complexity, and Search Power.

How excessive replica counts can degrade performance, and what to do about it

December 8, 2025

How excessive replica counts can degrade performance, and what to do about it

Learn about the impact of high replica counts in Elasticsearch, and how to ensure cluster stability by right-sizing your replicas.

How to deploy Elasticsearch on Azure AKS Automatic

November 14, 2025

How to deploy Elasticsearch on Azure AKS Automatic

Learn how to deploy Elasticsearch with Kibana on Azure using AKS Automatic and ECK for a partially managed Elasticsearch setup configuration.

Configuring recursive chunking for structured documents in Elasticsearch

November 11, 2025

Configuring recursive chunking for structured documents in Elasticsearch

Learn how to configure recursive chunking in Elasticsearch with chunk size, separator groups, and custom separator lists for optimal structured document indexing.

Ready to build state of the art search experiences?

Sufficiently advanced search isn’t achieved with the efforts of one. Elasticsearch is powered by data scientists, ML ops, engineers, and many more who are just as passionate about search as your are. Let’s connect and work together to build the magical search experience that will get you the results you want.

Try it yourself