This is a cache of https://www.elastic.co/guide/en/elasticsearch/reference/current/search-analyze.html. It is a snapshot of the page at 2024-11-13T00:55:06.284+0000.
Search and analyze data | Elasticsearch Guide [8.16] | Elastic

Search and analyze data

edit

You can use Elasticsearch as a basic document store to retrieve documents and their metadata. However, the real power of Elasticsearch comes from its advanced search and analytics capabilities.

You’ll use a combination of an API endpoint and a query language to interact with your data.

REST API

edit

Use REST APIs to manage your Elasticsearch cluster, and to index and search your data. For testing purposes, you can submit requests directly from the command line or through the Dev Tools Console in Kibana. From your applications, you can use a client in your programming language of choice.

Refer to first steps with Elasticsearch for a hands-on example of using the _search endpoint, adding data to Elasticsearch, and running basic searches in Query DSL syntax.

Query languages

edit

Elasticsearch provides a number of query languages for interacting with your data.

Query DSL is the primary query language for Elasticsearch today.

ES|QL is a new piped query language and compute engine which was first added in version 8.11.

ES|QL does not yet support all the features of Query DSL, like full-text search and semantic search. Look forward to new ES|QL features and functionalities in each release.

Refer to Query languages for a full overview of the query languages available in Elasticsearch.

Query DSL
edit

Query DSL is a full-featured JSON-style query language that enables complex searching, filtering, and aggregations. It is the original and most powerful query language for Elasticsearch today.

The _search endpoint accepts queries written in Query DSL syntax.

Search and filter with Query DSL
edit

Query DSL support a wide range of search techniques, including the following:

  • Full-text search: Search text that has been analyzed and indexed to support phrase or proximity queries, fuzzy matches, and more.
  • Keyword search: Search for exact matches using keyword fields.
  • Semantic search: Search semantic_text fields using dense or sparse vector search on embeddings generated in your Elasticsearch cluster.
  • Vector search: Search for similar dense vectors using the kNN algorithm for embeddings generated outside of Elasticsearch.
  • Geospatial search: Search for locations and calculate spatial relationships using geospatial queries.

Learn about the full range of queries supported by Query DSL.

You can also filter data using Query DSL. Filters enable you to include or exclude documents by retrieving documents that match specific field-level criteria. A query that uses the filter parameter indicates filter context.

Analyze with Query DSL
edit

Aggregations are the primary tool for analyzing Elasticsearch data using Query DSL. Aggregrations enable you to build complex summaries of your data and gain insight into key metrics, patterns, and trends.

Because aggregations leverage the same data structures used for search, they are also very fast. This enables you to analyze and visualize your data in real time. You can search documents, filter results, and perform analytics at the same time, on the same data, in a single request. That means aggregations are calculated in the context of the search query.

The folowing aggregation types are available:

  • Metric: Calculate metrics, such as a sum or average, from field values.
  • Bucket: Group documents into buckets based on field values, ranges, or other criteria.
  • Pipeline: Run aggregations on the results of other aggregations.

Run aggregations by specifying the search API's aggs parameter. Learn more in Run an aggregation.

ES|QL
edit

Elasticsearch Query Language (ES|QL) is a piped query language for filtering, transforming, and analyzing data. ES|QL is built on top of a new compute engine, where search, aggregation, and transformation functions are directly executed within Elasticsearch itself. ES|QL syntax can also be used within various Kibana tools.

The _query endpoint accepts queries written in ES|QL syntax.

Today, it supports a subset of the features available in Query DSL, like aggregations, filters, and transformations. It does not yet support full-text search or semantic search.

It comes with a comprehensive set of functions and operators for working with data and has robust integration with Kibana’s Discover, dashboards and visualizations.

Learn more in Getting started with ES|QL, or try our training course.

List of available query languages

edit

The following table summarizes all available Elasticsearch query languages, to help you choose the right one for your use case.

Name Description Use cases API endpoint

Query DSL

The primary query language for Elasticsearch. A powerful and flexible JSON-style language that enables complex queries.

Full-text search, semantic search, keyword search, filtering, aggregations, and more.

_search

ES|QL

Introduced in 8.11, the Elasticsearch Query Language (ES|QL) is a piped query language language for filtering, transforming, and analyzing data.

Initially tailored towards working with time series data like logs and metrics. Robust integration with Kibana for querying, visualizing, and analyzing data. Does not yet support full-text search.

_query

EQL

Event Query Language (EQL) is a query language for event-based time series data. Data must contain the @timestamp field to use EQL.

Designed for the threat hunting security use case.

_eql

Elasticsearch SQL

Allows native, real-time SQL-like querying against Elasticsearch data. JDBC and ODBC drivers are available for integration with business intelligence (BI) tools.

Enables users familiar with SQL to query Elasticsearch data using familiar syntax for BI and reporting.

_sql

Kibana Query Language (KQL)

Kibana Query Language (KQL) is a text-based query language for filtering data when you access it through the Kibana UI.

Use KQL to filter documents where a value for a field exists, matches a given value, or is within a given range.

N/A