0
0
Elasticsearchquery~5 mins

Multi-match query in Elasticsearch

Choose your learning style9 modes available
Introduction

A multi-match query helps you search for a word or phrase in many places at once. It makes finding information faster and easier.

You want to search for a keyword in both the title and description of products.
You need to find documents where a phrase appears in either the author name or content.
You want to search multiple fields like name, tags, and comments for a user query.
You want to rank results based on matches in several fields together.
Syntax
Elasticsearch
{
  "multi_match": {
    "query": "search text",
    "fields": ["field1", "field2", "field3"]
  }
}

The query is the word or phrase you want to find.

The fields list tells Elasticsearch where to look.

Examples
Searches for the word "apple" in both the title and description fields.
Elasticsearch
{
  "multi_match": {
    "query": "apple",
    "fields": ["title", "description"]
  }
}
Searches for the exact phrase "fresh orange" in the name and tags fields.
Elasticsearch
{
  "multi_match": {
    "query": "fresh orange",
    "fields": ["name", "tags"],
    "type": "phrase"
  }
}
Searches for "banana" giving double importance to matches in the title field.
Elasticsearch
{
  "multi_match": {
    "query": "banana",
    "fields": ["title^2", "description"]
  }
}
Sample Program

This query looks for the word "coffee" in the title, summary, and content fields of documents.

Elasticsearch
{
  "query": {
    "multi_match": {
      "query": "coffee",
      "fields": ["title", "summary", "content"]
    }
  }
}
OutputSuccess
Important Notes

You can boost some fields by adding ^number after the field name to make matches there count more.

Use the type option to change how the query matches, like "phrase" for exact phrases.

Multi-match queries are great for simple searches across many fields without writing multiple queries.

Summary

Multi-match queries let you search many fields at once with one query.

You specify the search word or phrase and the fields to check.

You can control importance and matching style with extra options.