0
0
Elasticsearchquery~5 mins

Match phrase query in Elasticsearch

Choose your learning style9 modes available
Introduction

A match phrase query helps you find documents where words appear together in the exact order you want.

You want to find a sentence or phrase exactly as typed in a document.
You need to search for a name or title that must appear in order.
You want to avoid results where words appear separately or in different places.
You are searching for a specific phrase in product descriptions.
You want to match quotes or fixed expressions in text.
Syntax
Elasticsearch
{
  "query": {
    "match_phrase": {
      "field_name": "your phrase here"
    }
  }
}

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

The phrase inside quotes is the exact sequence of words to match.

Examples
This searches the message field for the exact phrase "quick brown fox".
Elasticsearch
{
  "query": {
    "match_phrase": {
      "message": "quick brown fox"
    }
  }
}
This finds documents where the title field contains the phrase "Elasticsearch tutorial" exactly.
Elasticsearch
{
  "query": {
    "match_phrase": {
      "title": "Elasticsearch tutorial"
    }
  }
}
Sample Program

This query looks for documents where the description field contains the phrase "fresh organic apples" exactly as typed.

Elasticsearch
{
  "query": {
    "match_phrase": {
      "description": "fresh organic apples"
    }
  }
}
OutputSuccess
Important Notes

The match phrase query is stricter than a simple match query because it requires the words to be in order.

You can add a slop parameter to allow some words between the phrase words if needed.

Summary

Use match phrase query to find exact word sequences in text fields.

It helps when word order matters in your search.

It is useful for searching quotes, names, or fixed phrases.