0
0
Elasticsearchquery~5 mins

Full-text search engine concept in Elasticsearch

Choose your learning style9 modes available
Introduction

A full-text search engine helps you find words or phrases inside large amounts of text quickly and easily.

You want users to search articles or blog posts by keywords.
You need to find specific information inside product descriptions on a website.
You want to build a search box that can handle typos and different word forms.
You want to rank search results by how relevant they are to the query.
Syntax
Elasticsearch
{
  "query": {
    "match": {
      "field_name": "search text"
    }
  }
}

This is a basic search query in Elasticsearch using the match keyword.

Replace field_name with the text field you want to search.

Examples
Searches the title field for the words 'quick brown fox'.
Elasticsearch
{
  "query": {
    "match": {
      "title": "quick brown fox"
    }
  }
}
Searches the content field for the phrase 'Elasticsearch tutorial'.
Elasticsearch
{
  "query": {
    "match": {
      "content": "Elasticsearch tutorial"
    }
  }
}
Searches the description field for the words 'fast search'.
Elasticsearch
{
  "query": {
    "match": {
      "description": "fast search"
    }
  }
}
Sample Program

This example searches the summary field in the books index for the words 'adventure' and 'mystery'.

Elasticsearch will return books whose summaries contain these words, ranked by relevance.

Elasticsearch
POST /books/_search
{
  "query": {
    "match": {
      "summary": "adventure mystery"
    }
  }
}
OutputSuccess
Important Notes

Full-text search breaks text into words and finds matches, not just exact phrases.

It can handle different word forms, like 'run' and 'running'.

Search results are ranked by how well they match the query.

Summary

Full-text search helps find words inside large text quickly.

Elasticsearch uses queries like match to search text fields.

Results are ranked by relevance to show the best matches first.