0
0
Elasticsearchquery~5 mins

Match query in Elasticsearch

Choose your learning style9 modes available
Introduction

The match query helps you find documents that contain words similar to your search words. It looks for text that matches your search in a simple way.

When you want to search for documents containing a word or phrase in a text field.
When you want to find documents even if the words are slightly different or in a different order.
When you want to search user comments or reviews for certain keywords.
When you want to search product descriptions for relevant terms.
When you want to do a simple full-text search on a field.
Syntax
Elasticsearch
{
  "query": {
    "match": {
      "field_name": "search text"
    }
  }
}

Replace field_name with the name of the field you want to search.

Replace search text with the words you want to find.

Examples
This searches the title field for documents containing words like "quick", "brown", or "fox".
Elasticsearch
{
  "query": {
    "match": {
      "title": "quick brown fox"
    }
  }
}
This finds documents where the description field mentions "fresh" and "apples".
Elasticsearch
{
  "query": {
    "match": {
      "description": "fresh apples"
    }
  }
}
This searches the comments field for documents containing both "great" and "product".
Elasticsearch
{
  "query": {
    "match": {
      "comments": {
        "query": "great product",
        "operator": "and"
      }
    }
  }
}
Sample Program

This query looks for documents where the message field contains words like "hello" and "world".

Elasticsearch
{
  "query": {
    "match": {
      "message": "hello world"
    }
  }
}
OutputSuccess
Important Notes

The match query analyzes the search text, so it breaks it into words and looks for those words.

You can use the operator option to require all words (and) or any word (or).

Match query is good for full-text search but not for exact matches.

Summary

The match query finds documents with text similar to your search words.

It works well for searching text fields with multiple words.

You can control how words are combined using the operator option.