0
0
Elasticsearchquery~5 mins

First search query in Elasticsearch

Choose your learning style9 modes available
Introduction

You use a search query to find information stored in Elasticsearch quickly and easily.

You want to find all documents that match a specific word or phrase.
You need to search for data in a website's search box powered by Elasticsearch.
You want to filter results to show only items with certain properties.
You want to test if your Elasticsearch index contains the data you expect.
You want to explore how Elasticsearch returns matching documents.
Syntax
Elasticsearch
{
  "query": {
    "match": {
      "field_name": "search_text"
    }
  }
}

This is a simple JSON object sent to Elasticsearch to search.

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

Examples
Searches for documents where the title field contains the word "apple".
Elasticsearch
{
  "query": {
    "match": {
      "title": "apple"
    }
  }
}
Searches for documents where the description field contains the words "fresh" and "orange".
Elasticsearch
{
  "query": {
    "match": {
      "description": "fresh orange"
    }
  }
}
Sample Program

This example sends a search request to the fruits index to find documents where the name field contains "banana".

Elasticsearch
POST /fruits/_search
{
  "query": {
    "match": {
      "name": "banana"
    }
  }
}
OutputSuccess
Important Notes

Elasticsearch queries are written in JSON format.

The match query analyzes the search text and finds matching documents.

You can use other query types for more complex searches.

Summary

A first search query helps you find documents by matching text in a field.

Use the match query inside a query object in JSON.

Replace field names and search text to fit your data.