How full-text search works
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. Serverless interfaces and procedures might differ from classic Elastic Stack deployments. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability This functionality is generally available and ready for production usage. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Serverless
Generally available
Stack
Generally available
The following diagram illustrates the components of full-text search.
At a high level, full-text search involves the following:
- Text analysis: Analysis consists of a pipeline of sequential transformations. Text is transformed into a format optimized for searching using techniques such as stemming, lowercasing, and stop word elimination. Elasticsearch contains a number of built-in analyzers and tokenizers, including options to analyze specific language text. You can also create custom analyzers.
Refer to Test an analyzer to learn how to test an analyzer and inspect the tokens and metadata it generates.
Inverted index creation: After analysis is complete, Elasticsearch builds an inverted index from the resulting tokens. An inverted index is a data structure that maps each token to the documents that contain it. It’s made up of two key components:
- Dictionary: A sorted list of all unique terms in the collection of documents in your index.
- Posting list: For each term, a list of document IDs where the term appears, along with optional metadata like term frequency and position.
Relevance scoring: Results are ranked by how relevant they are to the given query. The relevance score of each document is represented by a positive floating-point number called the
_score. The higher the_score, the more relevant the document.The default similarity algorithm Elasticsearch uses for calculating relevance scores is Okapi BM25, a variation of the TF-IDF algorithm. BM25 calculates relevance scores based on term frequency, document frequency, and document length. Refer to this technical blog post for a deep dive into BM25.
Full-text search query: Query text is analyzed the same way as the indexed text, and the resulting tokens are used to search the inverted index.
Query DSL supports a number of full-text queries.
As of 8.17, ES|QL also supports full-text search functions.