What technology is Elasticsearch built on?
Reveal answer
On Apache Lucene, a Java library for text indexing and search; Solr and OpenSearch also derive from it.
Source: Notes, ch. 1 — Overview
July 20, 2025, 1:39 p.m.
Manning
A book about the ElasticSearch search engine, widely used for text search and logging across many organizations.
Progress saved only in this browser · log in to save it to your account
Uncheck to exclude.
No questions match these filters.
What technology is Elasticsearch built on?
On Apache Lucene, a Java library for text indexing and search; Solr and OpenSearch also derive from it.
Source: Notes, ch. 1 — Overview
What is the difference between searching structured and unstructured data?
In structured data (with a schema) the result is binary — it matches or not, with no relevance score; in unstructured data (text) one searches for identical and similar terms, with a relevance score.
Source: Notes, ch. 1 — Overview
Searching for "books published after 2015" and "books about concurrent programming": which is structured and which is not?
The first is structured (a precise filter on a date, yes/no); the second is unstructured text, with relevance.
Source: Notes, ch. 1 — Overview
Why are relational databases bad for text search?
They are slow to index large volumes of text, have no fuzzy matching or synonyms, search by exact match, and normalization makes searching several fields at once difficult.
Source: Notes, ch. 1 — Overview
What does making a text searchable mean, in essence?
Breaking it into tokens and mapping each token to the full documents that contain it.
Source: Notes, ch. 1 — Overview
What are the components of the Elastic Stack and the role of each?
Beats (ship data from somewhere), Logstash (ETL pipeline that transforms and transfers data), Elasticsearch (the search engine, heart of the stack) and Kibana (UI for visualizing and interacting).
Source: Notes, ch. 1 — Overview
You need to enrich and transform logs from several sources before indexing them. Which component of the stack do you use?
Logstash is the ETL engine; Beats only transport data and Kibana is the interface.
Source: Notes, ch. 1 — Overview
What are the three search scopes of Elastic Enterprise Search?
App Search (an application's internal data), Enterprise/Workplace Search (within the organization) and Site Search (on a website).
Source: Notes, ch. 1 — Overview
What should Elasticsearch not be used for?
Relational or transactional data, write-heavy workloads, OLAP, many binaries (images, video), low latency and real-time analytics, time series and graphs.
Source: Notes, ch. 1 — Overview
Elasticsearch is a good choice as the main database of a transactional payments system.
False: it is optimized for read-heavy workloads and search, not for transactional or relational data.
Source: Notes, ch. 1 — Overview
How do clients communicate with Elasticsearch?
Through RESTful APIs over HTTP, with JSON — which makes it language-agnostic.
Source: Notes, ch. 1 — Overview
What is the URL format for indexing a document with an ID?
PUT <index>/_doc/<id> with the JSON document in the body (e.g. PUT books/_doc/1).
Source: Notes, ch. 2 — Getting Started
In current versions, an index can hold several document types (such as books/novel/1).
False: types were removed; since 7.x only the _doc endpoint is used, one type per index.
Source: Notes, ch. 2 — Getting Started
Where does an index's schema come from if no mapping was defined?
It is inferred from the first document indexed (schema-free).
Source: Notes, ch. 2 — Getting Started
How do you count the documents of one index, of several, or of all?
GET books/_count, GET books1,books2/_count or GET _count.
Source: Notes, ch. 2 — Getting Started
How do you fetch several documents by ID at once?
With an ids query in the search API: {"query": {"ids": {"values": [1,2,3]}}}.
Source: Notes, ch. 2 — Getting Started
GET books/_search without a body is equivalent to which query?
To a match_all, which returns all documents.
Source: Notes, ch. 2 — Getting Started
In a match query with several words, what is the default operator and how do you change it?
OR; you can set "operator": "AND" to require all the words.
Source: Notes, ch. 2 — Getting Started
Why does searching "author": "JOSHUA" find "Joshua Bloch", but "josh" does not?
Analysis normalizes case, so JOSHUA becomes the token joshua; but "josh" is a different token — match does not search prefixes (for that there is the prefix query).
Source: Notes, ch. 2 — Getting Started
How do you search several fields while giving more weight to one of them?
multi_match with fields, using ^ for boost: "fields": ["title^3", "synopsis"].
Source: Notes, ch. 2 — Getting Started
What does match_phrase do, and what is slop for?
It searches for the exact phrase, in order; slop tolerates a number of missing or out-of-order words.
Source: Notes, ch. 2 — Getting Started
What is the fuzziness parameter?
An integer that allows matches up to that Levenshtein distance (character swaps, insertions, deletions) — it tolerates typos.
Source: Notes, ch. 2 — Getting Started
A user types "Kava" meaning "Java". What feature solves this?
One character swap is Levenshtein distance 1.
Source: Notes, ch. 2 — Getting Started
Why don't term queries give a meaningful relevance score?
Because they work on structured data with exact matching, without text analysis: the document matches or it doesn't.
Source: Notes, ch. 2 — Getting Started
What are the four clauses of a bool query, and which affect the score?
must (required, counts toward the score), must_not (excludes, no score), should (optional, only increases the score) and filter (required, no score).
Source: Notes, ch. 2 — Getting Started
You want books by Joshua, preferably tagged "Software", only 3rd edition, and none rated below 4.7. Build the logic of the bool query.
must: match author Joshua; should: match tags Software; filter: term edition 3; must_not: range amazon_rating lt 4.7.
Source: Notes, ch. 2 — Getting Started
What is the difference between putting a condition in must and in filter?
Both exclude what doesn't match, but filter doesn't contribute to the score (and can be cached); use it for yes/no conditions.
Source: Notes, ch. 2 — Getting Started
How do you get only the result of an aggregation, without the documents?
By setting "size": 0 in the request.
Source: Notes, ch. 2 — Getting Started
What is the difference between metric and bucket aggregations?
Metric aggregations compute statistics (min, max, avg, sum, stats); bucket aggregations split documents into groups (e.g. histogram, ranges).
Source: Notes, ch. 2 — Getting Started
What is the _bulk API for?
For indexing (or operating on) several documents in a single request.
Source: Notes, ch. 2 — Getting Started
What is an index in Elasticsearch?
A logical collection of documents — something like a table in a relational database.
Source: Notes, ch. 3 — Architecture
What is a shard?
An instance of Apache Lucene that holds part of an index's data; an index is divided into primary shards, each with replicas.
Source: Notes, ch. 3 — Architecture
What are the two steps of text analysis during indexing?
Tokenization (breaking the text into tokens, e.g. by whitespace) and normalization (enriching/transforming tokens: lowercasing, stemming, synonyms).
Source: Notes, ch. 3 — Architecture
Why does the query text also go through analysis?
So that it is tokenized and normalized the same way the documents were indexed; only then do the search tokens match those in the index.
Source: Notes, ch. 3 — Architecture
What is an inverted index?
A structure that maps each token to the documents in which it appears (and how often) — the basis of fast text search.
Source: Notes, ch. 3 — Architecture
Documents: 1 = "Hello WORLD", 2 = "Hello Mate". What does the inverted index look like with the standard analyzer?
hello → 1, 2; world → 1; mate → 2.
Source: Notes, ch. 3 — Architecture
What structure does Elasticsearch use for non-text data, such as numbers and dates?
BKD trees.
Source: Notes, ch. 3 — Architecture
What are replicas for?
Redundancy (they live on different nodes from the primary and can be promoted if a node goes down) and distributing reads.
Source: Notes, ch. 3 — Architecture
What is the default number of shards and replicas per index since version 7?
1 primary shard and 1 replica.
Source: Notes, ch. 3 — Architecture
Why can the number of shards not change in a live index, while the number of replicas can?
Because routing uses hash(id) % number_of_shards; changing the divisor would make documents unfindable. To change it, you have to reindex.
Source: Notes, ch. 3 — Architecture
An index with 3 shards is full and someone proposes going to 5 shards in the same index. What is the problem and the solution?
It is not possible: routing (hash(id) % 3) would send searches to the wrong shards. The solution is to create an index with 5 shards and reindex into it.
Source: Notes, ch. 3 — Architecture
What do the green, yellow and red states of a cluster mean?
Green: all shards and replicas allocated. Yellow: all primaries available, but some replica is not. Red: some primary shard unavailable.
Source: Notes, ch. 3 — Architecture
Why does a single-node cluster with 1-replica indexes turn yellow?
Because the replica cannot live on the same node as the primary; without another node, replicas are not allocated.
Source: Notes, ch. 3 — Architecture
What guidelines do the notes give for shard size and count?
Don't exceed about 50 GB per shard and host up to 20 shards per GB of heap.
Source: Notes, ch. 3 — Architecture
Name roles a node can have.
Master (cluster management), data (persistence and search; hot/cold variants), ingest (pipelines before indexing), ML, transform and coordinating (the default, receives client requests).
Source: Notes, ch. 3 — Architecture
What is a data stream?
A feature that works as an alias for automatically generated hidden indexes (e.g. one per day); writes go to the newest index and searches query all of them — ideal for time series and logs.
Source: Notes, ch. 3 — Architecture
What is an alias?
An alternative name for an index or set of indexes.
Source: Notes, ch. 3 — Architecture
What relevance algorithm does Elasticsearch use by default, and what does it take into account?
Okapi BM25, an improved version of TF/IDF: it rewards the term's frequency in the document, rewards terms that are rare in the index and normalizes by field length.
Source: Notes, ch. 3 — Architecture
Two documents contain "Java" once: one has 10 words, the other 1,000. Which does BM25 tend to score higher?
The short one: normalization by field length avoids favoring long documents, and the occurrence weighs more in a short text.
Source: Notes, ch. 3 — Architecture
What is the difference between scaling Elasticsearch vertically and horizontally?
Vertical: making the machine bigger (CPU, RAM), usually with downtime. Horizontal: adding nodes to the cluster — more practical and recommended.
Source: Notes, ch. 3 — Architecture
Running several nodes on the same machine is a good way to ensure redundancy.
False: if the machine goes down, they all go down; replicas should be on different machines.
Source: Notes, ch. 3 — Architecture
What is an index's mapping?
The schema definition: the fields, their data types and parameters; there is one mapping per index.
Source: Notes, ch. 4 — Mapping
What happens when you PUT a document into an index that does not exist?
The index is created with default settings, a schema is inferred from the document's types (dynamic mapping), and the document is indexed; subsequent documents skip the first steps.
Source: Notes, ch. 4 — Mapping
Why should dynamic mapping be kept for testing only?
Because it can get things wrong: for example, quoted numbers become strings and dates outside the default format (YYYY-MM-DD) are not recognized.
Source: Notes, ch. 4 — Mapping
The first document indexed has "price": "19.90" (in quotes). What will dynamic mapping do, and what problem does this cause?
It will infer text (with a keyword subfield), not a number; range searches and numeric aggregations on price won't work as expected.
Source: Notes, ch. 4 — Mapping
What is the difference between the text and keyword types?
text is analyzed (tokenized and normalized) for text search; keyword is not analyzed — the whole value becomes a single token, for exact matches (e.g. an email).
Source: Notes, ch. 4 — Mapping
What type should be used for an error code field like ERR-4021, searched only by equality?
Exact values that must not be broken into tokens are keyword.
Source: Notes, ch. 4 — Mapping
How do you sort results by a text field?
Better to use a keyword subfield (title.keyword); enabling fielddata: true also works, but is computationally expensive.
Source: Notes, ch. 4 — Mapping
Which APIs are used to define an explicit mapping?
The create index API (PUT employees with mappings) when the index doesn't exist, and the mapping API (PUT employees/_mapping) to update an existing one.
Source: Notes, ch. 4 — Mapping
It is possible to change the type of an existing field with PUT <index>/_mapping.
False: you can only add fields; to change a type you have to reindex.
Source: Notes, ch. 4 — Mapping
You need to change a field's type in production without breaking the clients that use the index name. How?
Create a new index with the correct mapping, reindex the data (_reindex API) and point an alias, used by the clients, to the new index.
Source: Notes, ch. 4 — Mapping
What is type coercion?
Elasticsearch slightly adapts the input data to fit the mapping's type, such as accepting "42" in a numeric field.
Source: Notes, ch. 4 — Mapping
What is the token_count type for?
For storing the number of tokens in a text; used as a subfield (e.g. title.word_count) to search, for example, for four-word titles.
Source: Notes, ch. 4 — Mapping
What is the constant_keyword type?
A keyword with a value predefined in the mapping, the same for all documents in the index; it can be omitted when indexing.
Source: Notes, ch. 4 — Mapping
What is the wildcard type for?
For searches with wildcard characters and regex over keyword values (e.g. *obj*).
Source: Notes, ch. 4 — Mapping
What are the range types (such as date_range)?
Fields with a lower and upper bound (e.g. the dates of a course), which can be queried with range queries.
Source: Notes, ch. 4 — Mapping
What does the geo_point type store, and what query does it enable?
Latitude and longitude; it enables searches such as geo_bounding_box.
Source: Notes, ch. 4 — Mapping
What is the limitation of the object type for arrays of objects?
Subfields are flattened into independent arrays, losing the link between values of the same object; a search combining two fields may match values from different objects.
Source: Notes, ch. 4 — Mapping
A document has [{dish: burger, extra: pickles}, {dish: hotdog, extra: chili}]. Does searching for "burger with chili" return the document?
With the object type, yes (the values are flattened); with nested, no — each object is treated separately.
Source: Notes, ch. 4 — Mapping
What is the nested type?
A specialized form of object that preserves the relationship between the fields of each object in an array; it must be declared in the mapping.
Source: Notes, ch. 4 — Mapping
Elasticsearch has its own array data type.
False: any field accepts multiple values, as long as they are of the same type.
Source: Notes, ch. 4 — Mapping
What does the flattened type do?
It indexes all subfields of an object as keywords, without analysis and without declaring them in the mapping; it allows searching any value without knowing the keys.
Source: Notes, ch. 4 — Mapping
Medical notes come in with unpredictable keys (symptoms, medication, history…) and you only need to search exact values. What type should you use?
flattened: it avoids a mapping explosion and makes any value searchable as a keyword.
Source: Notes, ch. 4 — Mapping
How does the join type work, and what is its downside?
It creates a parent-child relationship between documents in the same index (with routing so they land on the same shard); performance is poor, and it is usually better to leave this to relational databases.
Source: Notes, ch. 4 — Mapping
How does the search_as_you_type type support autocomplete?
It creates subfields automatically: 2- and 3-word shingles (_2gram, _3gram) and edge n-grams (_index_prefix), to match what the user is typing.
Source: Notes, ch. 4 — Mapping
How can a field have several types?
By declaring subfields in fields in the mapping — for example, subject as text, subject.kw as keyword and subject.comp as completion.
Source: Notes, ch. 4 — Mapping
What are the three basic configurations of an index?
Settings (e.g. shards and replicas), mappings (schema) and aliases.
Source: Notes, ch. 6 — Indexing operations
What is the risk of fully disabling action.auto_create_index?
Breaking tools such as Kibana, which create hidden indexes (starting with a dot) automatically; it is better to allow it selectively by name patterns.
Source: Notes, ch. 6 — Indexing operations
What is the difference between dynamic and static settings?
Dynamic ones can change in a live index; static ones only at creation — to change them you have to close the index or recreate it.
Source: Notes, ch. 6 — Indexing operations
What are the steps of a zero-downtime index migration?
Clients query through an alias; create the new index with the desired settings; reindex the data; repoint the alias (with _aliases, an atomic remove + add); finally delete the old one.
Source: Notes, ch. 6 — Indexing operations
What is is_write_index for in an alias that points to several indexes?
To indicate which of them receives writes; at least one must be writable.
Source: Notes, ch. 6 — Indexing operations
What happens when you close an index (POST cars/_close)?
It stops accepting reads and writes and frees memory and resources; it can be reopened with _open.
Source: Notes, ch. 6 — Indexing operations
What does action.destructive_requires_name control?
Whether destructive operations (delete, close) require explicit names or accept wildcards and _all.
Source: Notes, ch. 6 — Indexing operations
What is an index template?
Predefined configurations (settings, mappings, aliases) applied automatically to indexes whose name matches a pattern (glob).
Source: Notes, ch. 6 — Indexing operations
What is the difference between a component template and a composable (index) template?
The component is a reusable block of configurations, without an index pattern, which is not a template on its own; the composable one has an index pattern and is made up of zero or more components (composed_of).
Source: Notes, ch. 6 — Indexing operations
An index matches two templates, with priority 20 and 30, that set the number of replicas differently. Which applies?
The configurations of both are applied, but in a conflict the priority-30 one prevails; explicit configurations at creation beat any template.
Source: Notes, ch. 6 — Indexing operations
What are the conditions for splitting an index?
The index must be read-only (index.blocks.write), the target must not exist, the target's number of shards must be a multiple of the original's and the node must have space.
Source: Notes, ch. 6 — Indexing operations
What are the conditions for shrinking an index?
Read-only source, all shards on the same node, nonexistent target, target's number of shards a factor of the original's and enough memory on the node.
Source: Notes, ch. 6 — Indexing operations
An index has 3 shards. To which number can it be split?
The target must have a number of shards that is a multiple of the original and not smaller: 12 = 3 × 4.
Source: Notes, ch. 6 — Indexing operations
What does rolling over an alias do?
It makes the current index read-only, creates a new index with an incremented name (e.g. -000002) and repoints the alias to it; the data is not copied.
Source: Notes, ch. 6 — Indexing operations
Application logs arrive continuously and you want a new index whenever the current one goes over 10 GB or one day. How do you set this up?
An ILM policy with a rollover action (max_size, max_age) in the hot phase, attached via a template (with rollover_alias) to indexes matching the pattern, and an initial writable index on the alias.
Source: Notes, ch. 6 — Indexing operations
What are the phases of an index's life cycle in ILM?
Hot (read and write), warm (read-only, frequent queries), cold (read-only, rare and slow queries), frozen (very rare and very slow) and delete.
Source: Notes, ch. 6 — Indexing operations
The hot phase is the only mandatory one in an ILM policy.
True: the index can stay hot forever or move to any optional phase.
Source: Notes, ch. 6 — Indexing operations
Why might an ILM action not happen at the exact expected moment?
Because policies run as a background task, checked every 10 minutes by default.
Source: Notes, ch. 6 — Indexing operations
When do you index with PUT and when with POST?
PUT when the client provides the ID (PUT movies/_doc/1); POST when the ID should be generated by the server (a UUID).
Source: Notes, ch. 5 — Working with documents
How do you avoid overwriting an existing document when indexing?
By using _create (PUT movies/_create/100), which errors if the ID already exists; the regular _doc overwrites.
Source: Notes, ch. 5 — Working with documents
What happens to a document between indexing and becoming searchable?
It goes into the shard's in-memory buffer; at each refresh (1 s by default) the documents become a segment with an inverted index, searchable, and are later persisted to disk.
Source: Notes, ch. 5 — Working with documents
How does Lucene manage segments over time?
It merges segments — three at a time — into larger segments, recursively; deleted documents are only marked and actually removed during merges.
Source: Notes, ch. 5 — Working with documents
Why is Elasticsearch said to be eventually consistent?
Because an indexed document only becomes searchable after the next refresh, not immediately.
Source: Notes, ch. 5 — Working with documents
What is the trade-off of lowering the refresh interval?
Documents become searchable sooner, but frequent refreshes are expensive in I/O.
Source: Notes, ch. 5 — Working with documents
You are going to load 10 million documents at once. What should you do with refresh?
Disable it (or greatly increase the interval) during the load and re-enable it at the end, making everything searchable at once and saving I/O.
Source: Notes, ch. 5 — Working with documents
What are the values of the ?refresh parameter when indexing?
true (searchable immediately), false (default) and wait_for (the request waits for the next refresh).
Source: Notes, ch. 5 — Working with documents
How do you check only whether a document exists?
HEAD movies/_doc/1.
Source: Notes, ch. 5 — Working with documents
How do you fetch several documents by ID, including from different indexes?
With _mget: in one index, {"ids": [...]}; in several, a docs list with each one's _index and _id.
Source: Notes, ch. 5 — Working with documents
How do you control what comes back in the response to a document GET?
_source instead of _doc returns only the document without metadata; ?_source=false returns only metadata; _source_includes and _source_excludes filter fields.
Source: Notes, ch. 5 — Working with documents
What does the _update API do behind the scenes?
It fetches the document, modifies it and reindexes it — it is a replacement.
Source: Notes, ch. 5 — Working with documents
What are the parts of an update script?
source (the logic, e.g. ctx._source.actors.add(...)), lang (painless is the default) and params (values passed dynamically).
Source: Notes, ch. 5 — Working with documents
Why pass values in params instead of hardcoding them in the script?
Because scripts are compiled on first execution, which is expensive; with parameters, the same compiled script is reused for different values.
Source: Notes, ch. 5 — Working with documents
How does upsert work?
If the document doesn't exist, it inserts the content of upsert; if it exists, it applies the update script.
Source: Notes, ch. 5 — Working with documents
What does doc_as_upsert: true do in a partial update?
If the document doesn't exist, it creates it with the content of doc, instead of erroring.
Source: Notes, ch. 5 — Working with documents
How do you update several documents without knowing their IDs?
With _update_by_query: a query selects the documents and a script modifies them; there is version checking with retry, and only the documents with errors fail to be updated.
Source: Notes, ch. 5 — Working with documents
How do you delete documents by criteria?
With _delete_by_query, which accepts any query (ranges, bool etc.); with match_all it deletes everything. Deletion is irreversible.
Source: Notes, ch. 5 — Working with documents
What is the format of a _bulk request?
NDJSON: for each operation, an action and metadata line (index, create, update, delete with _index and _id) followed, when applicable, by a line with the document.
Source: Notes, ch. 5 — Working with documents
Why use _bulk instead of indexing document by document?
To save bandwidth and requests when operating at scale.
Source: Notes, ch. 5 — Working with documents
What are the three components of an analyzer, and how many of each can there be?
Character filters (zero or more), exactly one tokenizer, and token filters (zero or more), in that order.
Source: Notes, ch. 7 — Text analysis
In an analyzer, which component removes HTML tags before breaking up the text?
Character filters act on characters before tokenization.
Source: Notes, ch. 7 — Text analysis
What tokens come out of <h2>Hello WORLD</h2> with html_strip, the whitespace tokenizer and lowercase?
hello and world.
Source: Notes, ch. 7 — Text analysis
What is the _analyze endpoint for?
For testing analyzers, tokenizers and filters on ad hoc text, without changing indexes or the cluster.
Source: Notes, ch. 7 — Text analysis
What is the standard analyzer like?
The default: no character filters, the standard tokenizer (whitespace, grammar, punctuation) and the lowercase and stop token filters — the latter disabled by default.
Source: Notes, ch. 7 — Text analysis
With the standard analyzer, what happens to "Hot cup of ☕ and a 🍿 is a Weird Combo :(!!"?
They become lowercase tokens; emojis such as ☕ and 🍿 are kept as tokens, but ":(" and "!!" are removed; stop words ("of", "a") remain.
Source: Notes, ch. 7 — Text analysis
What does the simple analyzer do?
Only a lowercase tokenizer, which splits on any non-letter (spaces, hyphens, numbers), with no filters.
Source: Notes, ch. 7 — Text analysis
What tokens does the simple analyzer produce for "Lukša's K8s in Action"?
lukša, s, k, s, in, action: the apostrophe and the number 8 become separators.
Source: Notes, ch. 7 — Text analysis
What does the keyword analyzer do?
It uses a noop tokenizer: the whole text becomes a single token, with no filters; it requires an exact match.
Source: Notes, ch. 7 — Text analysis
What does the fingerprint analyzer do, and what is it for?
It removes duplicates, sorts the words and produces a single token; useful for detecting duplicate items.
Source: Notes, ch. 7 — Text analysis
What tokens does a pattern analyzer splitting on hyphens produce for "1234-5678-9000-0000"?
1234, 5678, 9000, 0000.
Source: Notes, ch. 7 — Text analysis
Why can a language analyzer's stemming get in the way, and how do you fix it?
It can be too aggressive: "authorization" and "authority" both become "author", making them indistinguishable; stem_exclusions is used.
Source: Notes, ch. 7 — Text analysis
How do you enable stop words in the standard analyzer?
By defining in the index settings an analyzer of type standard with "stopwords": "_english_" (or a custom list/file).
Source: Notes, ch. 7 — Text analysis
How do you create a custom analyzer?
In the index settings, an analyzer with "type": "custom", listing the desired char_filter, tokenizer and filter.
Source: Notes, ch. 7 — Text analysis
At what levels is the indexing analyzer defined?
At the index (analysis.analyzer.default, applies to all text fields) or at the field (in the mapping).
Source: Notes, ch. 7 — Text analysis
In what order does Elasticsearch choose the analyzer at search time?
1) the query's; 2) the field's search_analyzer; 3) the index's default search_analyzer; 4) the field's or index's indexing analyzer.
Source: Notes, ch. 7 — Text analysis
A field has analyzer: stop and search_analyzer: simple, and the query does not specify an analyzer. Which one analyzes the search text?
simple: the field's search_analyzer takes priority over the indexing analyzer.
Source: Notes, ch. 7 — Text analysis
What are the three types of character filter?
HTML strip (removes tags), mapping (swaps characters/terms, e.g. UK → United Kingdom) and pattern replace (replaces by regex).
Source: Notes, ch. 7 — Text analysis
What are the bigrams and the edge n-grams of "coffee"?
Bigrams: co, of, ff, fe, ee. Edge n-grams: c, co, cof, coff, coffe, coffee — anchored at the start of the word.
Source: Notes, ch. 7 — Text analysis
For an autocomplete that suggests "elasticsearch" when the user types "elas", which tokenizer should be used at indexing?
Edge n-gram: it indexes the prefixes, so "elas" matches the generated token.
Source: Notes, ch. 7 — Text analysis
What are the uax_url_email and path_hierarchy tokenizers for?
uax_url_email keeps URLs and emails as tokens; path_hierarchy breaks hierarchical paths (folders) at the separators.
Source: Notes, ch. 7 — Text analysis
What does the shingle token filter do?
It generates word n-grams (not character ones): "James Bond" → ["james", "james bond", "bond"]; by default of 1 and 2 words.
Source: Notes, ch. 7 — Text analysis
How does the synonym token filter work?
It turns words into their synonyms based on a list, inline or in a file.
Source: Notes, ch. 7 — Text analysis
What is the difference between precision and recall?
Precision is the density of relevant documents among those returned; recall is how much of the existing relevant documents was returned.
Source: Notes, ch. 8 — Introducing search
How does enabling synonyms and fuzziness in a search tend to affect precision and recall?
It tends to increase recall (finds more relevant documents) and reduce precision (more irrelevant results come in).
Source: Notes, ch. 8 — Introducing search
What is the role of the coordinating node in a search?
To find the nodes with relevant shards, ask them to run the query, receive the partial results, aggregate them and respond to the client. Any node can be a coordinator.
Source: Notes, ch. 8 — Introducing search
What is the difference between query context and filter context?
Query context computes a relevance score; filter context only decides whether the document is included, without a score, saving resources and using the cache.
Source: Notes, ch. 8 — Introducing search
What is a URI request search, and what are its limitations?
Searching with parameters in the URL (?q=title:Godfather); it supports boolean operators, ranges and default_operator, but is less flexible than the Query DSL.
Source: Notes, ch. 8 — Introducing search
What is the difference between a leaf query and a compound query?
A leaf query has a single criterion; a compound query combines several leaf queries with conditions.
Source: Notes, ch. 8 — Introducing search
How does result pagination work, and what is the default limit?
With size (default 10) and from; the default maximum is 10,000 results (adjustable, but not recommended). For many results, search_after is more efficient.
Source: Notes, ch. 8 — Introducing search
You need to go through 2 million documents from a search. Why not use from/size?
Because deep from is expensive (each page requires sorting everything before it) and hits the 10,000 limit; use search_after.
Source: Notes, ch. 8 — Introducing search
What does highlighting do?
It highlights, in the specified fields, the passages that matched the search, by default wrapping them in <em> tags.
Source: Notes, ch. 8 — Introducing search
What does explain: true do in a search?
It explains how each result's score was computed (boost × IDF × TF); there is also the _explain API.
Source: Notes, ch. 8 — Introducing search
What happens to _score when sorting by another field?
It is not computed, unless track_scores: true is used; additional sort fields serve as tie-breakers.
Source: Notes, ch. 8 — Introducing search
What options are there for controlling the fields returned in a search?
_source: false (omits the document), fields (a subset of fields, accepts wildcards), _source with includes/excludes and script_fields (fields computed by a script).
Source: Notes, ch. 8 — Introducing search
What is indices_boost for?
To prioritize results from certain indexes, multiplying the score of each index's documents by a coefficient.
Source: Notes, ch. 8 — Introducing search
What are the characteristics of term-level queries?
They do exact matching on structured data (numbers, dates, keywords), without going through the analyzer — the term is looked up directly in the inverted index; they are cheaper.
Source: Notes, ch. 9 — Term-level search
Why does term: {title: "The Godfather"} on a text field probably return nothing?
Because the field was analyzed and indexed as separate lowercase tokens ("the", "godfather"); the term query does not analyze and looks for the exact string, which doesn't exist in the index.
Source: Notes, ch. 9 — Term-level search
In a term query, uppercase and lowercase make a difference.
True: since the query doesn't go through the analyzer, "R" and "r" are different terms.
Source: Notes, ch. 9 — Term-level search
What does the terms query do?
It searches for several values in the same field, with OR logic (e.g. certificate in ["PG-13", "R"]); the maximum number of terms is configurable (default 2^16).
Source: Notes, ch. 9 — Term-level search
What is a terms lookup?
A terms query whose values come from a field of another document (index, id, path), instead of a fixed list.
Source: Notes, ch. 9 — Term-level search
What is the exists query for?
For returning documents in which a field exists; combined with must_not, it finds those that lack the field.
Source: Notes, ch. 9 — Term-level search
What does the range query do, and which operators does it use?
It searches for values within bounds with gt, gte, lt and lte; it accepts date expressions such as now-1y.
Source: Notes, ch. 9 — Term-level search
How do you search for movies released in the last year?
range on release_date with "gte": "now-1y".
Source: Notes, ch. 9 — Term-level search
What are the operators of the wildcard query, and what is its cost?
* (zero or more characters) and ? (one character); it is expensive and can be blocked with search.allow_expensive_queries: false.
Source: Notes, ch. 9 — Term-level search
How do you speed up prefix queries?
By setting index_prefixes in the field's mapping: the prefixes (by default from 2 to 5 characters) are pre-indexed, avoiding computing them at search time.
Source: Notes, ch. 9 — Term-level search
With the default index_prefixes, which prefixes are pre-indexed for "Gladiator"?
"Gl", "Gla", "Glad", "Gladi" (from 2 to 5 characters).
Source: Notes, ch. 9 — Term-level search
How does fuzziness: auto work?
It sets the edit distance by the term's length: 0–2 characters → 0; 3–5 → 1; more than 5 → 2. It is the default of the fuzzy query.
Source: Notes, ch. 9 — Term-level search
With fuzziness: auto, how many edits are tolerated for the term "rama"?
"rama" has 4 characters (the 3–5 band): distance 1 — it finds "drama".
Source: Notes, ch. 9 — Term-level search
What would a match_none query be for?
To deliberately return no results, combined with application logic — for example, during maintenance, instead of erroring.
Source: Notes, ch. 10 — Full-text searches
In a match with the OR operator, how do you require at least some of the words to match?
With minimum_should_match, which sets the minimum number of terms that must match.
Source: Notes, ch. 10 — Full-text searches
Are the terms of a match query analyzed?
Yes: they go through the analyzer (by default the same as at indexing, with lowercase), unlike term-level queries.
Source: Notes, ch. 10 — Full-text searches
What is the difference between match with the AND operator and match_phrase?
AND requires all the words in any order and position; match_phrase requires the words together, in the same sequence (relaxable with slop).
Source: Notes, ch. 10 — Full-text searches
What does match_phrase_prefix do?
Like match_phrase, but the last word can be just a prefix: "Concepts and found" matches "Concepts and foundations".
Source: Notes, ch. 10 — Full-text searches
What is the default type of multi_match, and how does it compute the score?
best_fields: the score is that of the best-matching field, ignoring the others; there are also cross_fields, most_fields, phrase and phrase_prefix.
Source: Notes, ch. 10 — Full-text searches
Which query does multi_match use behind the scenes, and what is tie_breaker for?
dis_max, which runs one query per field and keeps the best score; tie_breaker multiplies the scores of the other fields and adds them, serving as a tie-breaker.
Source: Notes, ch. 10 — Full-text searches
Two books have "Design Patterns" in the title with the same score, but only one also has it in the synopsis. How do you make the second field count?
Use a tie_breaker (e.g. 0.3) in the dis_max/multi_match: the score of the fields that are not the best now counts partially.
Source: Notes, ch. 10 — Full-text searches
What is the query_string query, and what is its downside?
A query with operator syntax (AND, OR, NOT, fields, ranges, ~ for fuzzy), useful for advanced user searches; it is strict about syntax and throws an exception if the input is malformed.
Source: Notes, ch. 10 — Full-text searches
When should you prefer simple_query_string to query_string?
When the input comes from the user and you don't want syntax errors: it accepts few operators (e.g. + for AND) and suppresses syntax errors.
Source: Notes, ch. 10 — Full-text searches
A public search box receives free text with unbalanced quotes and parentheses. Which query avoids 400 errors?
simple_query_string ignores syntax errors instead of throwing an exception.
Source: Notes, ch. 10 — Full-text searches
What are the five types of compound query?
bool, constant_score, function_score, boosting and dis_max.
Source: Notes, ch. 11 — Compound queries
How does the behavior of should change when there is no must?
It starts working as a filter: minimum_should_match goes from 0 to 1, so at least one should clause must match.
Source: Notes, ch. 11 — Compound queries
What are named queries for in a bool query?
For naming each leaf query; the response indicates which of them matched in each result.
Source: Notes, ch. 11 — Compound queries
What is the constant_score query for?
For wrapping a filter and assigning a fixed (non-zero) score to the results, bypassing relevance computation.
Source: Notes, ch. 11 — Compound queries
How does the boosting query work?
It has a positive part (what to return) and a negative one (what to demote); results matching the negative part have their score multiplied by negative_boost.
Source: Notes, ch. 11 — Compound queries
You want to list all TVs, but show those above US$2,500 further down, without excluding them. Which query should you use?
boosting: positive = product TV; negative = range price > 2500, with a negative_boost of, for example, 0.5.
Source: Notes, ch. 11 — Compound queries
What does the function_score query allow?
Defining a custom score: random (random_score, with a seed), by script (script_score) or by a field's value (field_value_factor).
Source: Notes, ch. 11 — Compound queries
You want TVs with better user ratings to come first, without writing a script. What should you use?
function_score with field_value_factor on user_ratings (optionally with a factor or a modifier such as square).
Source: Notes, ch. 11 — Compound queries
What do score_mode and boost_mode control in function_score?
score_mode defines how to combine the scores of several functions; boost_mode, how to combine them with the query's score (multiplication by default; also sum, avg, min, max, replace).
Source: Notes, ch. 11 — Compound queries
What are the three main geo queries, and what does each search for?
geo_bounding_box (within a rectangle defined by two corners), geo_distance (within a circle of given radius around a point) and geo_shape (shapes in relation to another shape).
Source: Notes, ch. 12 — Advanced search
An app wants to list restaurants within 2 km of the user. Which query should it use?
geo_distance searches within a circle around a point, with a radius in km or miles.
Source: Notes, ch. 12 — Advanced search
In what formats can a geo_point be given?
A "lat, lon" string, a {lat, lon} object, an array (longitude first), WKT (POINT(lon lat)) or a geohash.
Source: Notes, ch. 12 — Advanced search
Which spatial relations does the geo_shape query support?
intersects (default, any point in common), within (entirely inside), contains (contains the query's shape) and disjoint (outside).
Source: Notes, ch. 12 — Advanced search
You want the land plots entirely inside a neighborhood polygon, excluding those that cross the border. Which relation should you use?
within; the default intersects would also include plots that only touch or cross the border.
Source: Notes, ch. 12 — Advanced search
What is the shape query for?
For searching 2D shapes on a Cartesian plane (e.g. technical drawings), not a geographic one — for example, all shapes within an envelope.
Source: Notes, ch. 12 — Advanced search
What is the difference between a regular query and a span query?
The regular one asks whether the document contains "apple" and "pie"; the span one considers position: "apple" immediately followed by "pie", or within 3 words.
Source: Notes, ch. 12 — Advanced search
What do span_first, span_near and span_within do?
span_first: a term among the first n words. span_near: terms within n positions of each other (with slop and in_order). span_within: a term surrounded by two others.
Source: Notes, ch. 12 — Advanced search
How do you find quotes in which "plato" appears before "aristotle", with up to 3 words between them?
span_near with two span_terms (plato, aristotle), slop: 3 and in_order: true.
Source: Notes, ch. 12 — Advanced search
What does the distance_feature query do?
It boosts the score of documents closer to an origin (location or date), with a distance pivot.
Source: Notes, ch. 12 — Advanced search
What is the pinned query for?
For pinning certain documents (by ID) to the top, regardless of the organic search score — for example, sponsored results.
Source: Notes, ch. 12 — Advanced search
What does the more_like_this query do?
It searches for documents similar to a given text or document, in the specified fields.
Source: Notes, ch. 12 — Advanced search
How does the percolate query invert the usual logic of search?
Instead of indexing documents and searching them with queries, queries are indexed in a percolator index and you search with a document, finding out which queries it satisfies.
Source: Notes, ch. 12 — Advanced search
Users searched for a book that didn't exist; now it has arrived in stock. How do you notify them?
Store those searches in a percolator index; when indexing the new book, run a percolate query with it to find the searches it satisfies and notify their authors.
Source: Notes, ch. 12 — Advanced search
What are the three types of aggregation?
Metric (sums, averages, minimum…), bucket (grouping documents into intervals/categories) and pipeline (operating on the result of other aggregations).
Source: Notes, ch. 13 — Aggregations
What happens when you combine query and aggs in the same request?
The aggregations are computed over the documents that match the query.
Source: Notes, ch. 13 — Aggregations
Why does aggregating on a text field give an error, and what is the workaround?
Text fields have no doc values for aggregation; you can enable fielddata in the mapping, but it is expensive — the best is to aggregate on the keyword subfield.
Source: Notes, ch. 13 — Aggregations
What do the stats, extended_stats and cardinality aggregations return?
stats: several statistics at once (min, max, avg, sum, count); extended_stats: even more (variance, deviation…); cardinality: the number of unique values.
Source: Notes, ch. 13 — Aggregations
How do you define the buckets of a histogram?
By a fixed interval (interval) or by manual ranges (ranges); for dates, date_histogram with calendar_interval (calendar-aware) or fixed_interval.
Source: Notes, ch. 13 — Aggregations
You want to count customers in age bands 0–18, 18–30, 30–60, 60+. histogram or range?
range: the bands have different widths; histogram only creates fixed-size intervals.
Source: Notes, ch. 13 — Aggregations
Why use calendar_interval: 1M instead of fixed_interval: 30d for monthly sales?
Because months have different lengths; calendar_interval respects calendar months, while a fixed 30 days misaligns the buckets.
Source: Notes, ch. 13 — Aggregations
What is a sub-aggregation?
An aggregation nested inside a bucket — for example, the average rating within each year of a date_histogram.
Source: Notes, ch. 13 — Aggregations
What does the terms aggregation (and multi_terms) do?
It creates one bucket per value of a field (e.g. one per author); multi_terms groups by combinations of several fields.
Source: Notes, ch. 13 — Aggregations
What is the difference between parent and sibling aggregations?
Parent operates inside another aggregation (e.g. average per day, nested); sibling runs in parallel, at the same level, over the same set (e.g. average and histogram side by side).
Source: Notes, ch. 13 — Aggregations
What does the cumulative_sum pipeline do?
It is a parent pipeline that computes the running total of a metric across buckets (e.g. cappuccinos sold up to each day), referencing it through buckets_path.
Source: Notes, ch. 13 — Aggregations
How do you find the day with the most cappuccino sales, and how do you reference the metric?
With a max_bucket sibling pipeline whose buckets_path is sales_by_coffee>cappuccino_sales — the > separates the bucket aggregation from the metric.
Source: Notes, ch. 13 — Aggregations
How do you find out why a shard was not allocated?
With GET _cluster/allocation/explain, giving the index, shard and whether it is primary; the response brings the deciders' decisions (e.g. same_shard: there is already a copy on the node).
Source: Notes, ch. 14 — Administration
What happens when a second node joins a single-node cluster?
Shards are reallocated automatically: replicas, previously unallocated, come to exist on the new node and some primaries may be moved to it.
Source: Notes, ch. 14 — Administration
Does increasing replicas improve reads, writes or both?
Only reads: replicas serve queries, but every write must be done on the primary and replicated, which can even weigh more.
Source: Notes, ch. 14 — Administration
What are Elasticsearch's default communication ports?
9200 for HTTP (REST) clients and 9300 for communication between nodes (transport).
Source: Notes, ch. 14 — Administration
An index has 10 shards of 30 GB, each with 2 replicas. How much space does it need at minimum?
900 GB: 10 primaries × 30 GB = 300 GB, plus 20 replicas × 30 GB = 600 GB — replicas require the same resources as primaries.
Source: Notes, ch. 14 — Administration
What are snapshots in Elasticsearch?
Incremental backups of one index, several or the whole cluster (including templates and ILM policies), in a local or cloud repository (e.g. S3), restored via _restore.
Source: Notes, ch. 14 — Administration
What is SLM for?
Snapshot Lifecycle Management (_slm): it automates snapshots with scheduling and retention policies; it can be triggered manually.
Source: Notes, ch. 14 — Administration
How do snapshots help change settings that cannot be altered in a live index?
You create a new index with the right settings, snapshot the old one and restore the data into the new one.
Source: Notes, ch. 14 — Administration
What are Elasticsearch's three configuration files?
elasticsearch.yml (basic settings: cluster name, ports, paths), log4j2.properties (log levels) and jvm.options (heap and JVM).
Source: Notes, ch. 14 — Administration
What rules apply to configuring the JVM heap?
Never edit the original jvm.options — create a .options file in jvm.options.d — and never set -Xms/-Xmx above 50% of the node's RAM.
Source: Notes, ch. 14 — Administration
When raising the log level to DEBUG to investigate a problem, why use a transient setting?
So that the change does not persist after the cluster restarts, going back to INFO without having to remember to undo it.
Source: Notes, ch. 14 — Administration
What is a master-eligible node, and how is the master chosen?
A node that can become master; the master is chosen by election among them at startup or when the current one goes down. Only the master changes the cluster state and communicates it to the others.
Source: Notes, ch. 14 — Administration
What is the master quorum, and why are at least three master-eligible nodes recommended?
The minimum number of master-eligible nodes (half + 1) that must agree to elect the master or confirm the cluster state; with three or more, split brain — two simultaneous masters during a network failure — is avoided.
Source: Notes, ch. 14 — Administration
With 5 master-eligible nodes, what is the quorum?
3 (5/2 + 1, rounding the half down).
Source: Notes, ch. 14 — Administration
Why is it a good idea to have dedicated master nodes?
Because nodes can take on several roles, but at a performance cost; the master is critical and should not compete for resources with data and searches.
Source: Notes, ch. 14 — Administration
What hardware measures help search speed?
SSDs and plenty of memory; a heap of about half the node's RAM (less garbage collection); evenly sized shards, since many small shards increase communication between nodes.
Source: Notes, ch. 15 — Performance and troubleshooting
Why should data in Elasticsearch be denormalized?
Because it is NoSQL and does not do joins efficiently: each document should be self-sufficient, with no hierarchy between documents.
Source: Notes, ch. 15 — Performance and troubleshooting
How do you avoid searching many fields at once?
By using copy_to in the mapping to combine several fields into one and searching that field — cheaper than a multi_match over many fields.
Source: Notes, ch. 15 — Performance and troubleshooting
Why does using keyword for exact searches improve performance?
Because it skips the text analysis step.
Source: Notes, ch. 15 — Performance and troubleshooting
What measures speed up indexing?
System-generated IDs (no need to check uniqueness), the bulk API (with a size limit), refresh disabled or less frequent during the load and tuning the thread pools.
Source: Notes, ch. 15 — Performance and troubleshooting
What is the trade-off of using IDs generated by Elasticsearch?
It indexes faster, since it doesn't need to check whether the ID already exists, but it is liable to duplicate documents that would be the same.
Source: Notes, ch. 15 — Performance and troubleshooting
What are the three disk watermarks, and what happens at each one?
Low (85%): the node stops receiving new shards. High (90%): shards start being relocated to other nodes. Flood stage (95%): the node's indexes become read-only until space is freed.
Source: Notes, ch. 15 — Performance and troubleshooting
A node is at 96% disk usage and writes start to fail. What happened?
Above 95% (flood stage), the node's indexes become read-only.
Source: Notes, ch. 15 — Performance and troubleshooting
What are Elasticsearch's circuit breakers for?
For blocking operations that would exceed memory limits, returning an error before executing them, instead of bringing the node down with an out-of-memory error.
Source: Notes, ch. 15 — Performance and troubleshooting
Name types of circuit breaker and their default limits.
Parent (70% of the heap, with real memory), request (60%), fielddata (40%), in-flight requests and accounting (inherit from parent) and script compilation (150 compilations every 5 min).
Source: Notes, ch. 15 — Performance and troubleshooting
What happens to reads and writes when there are unallocated primary shards?
They are blocked for those shards until they are properly allocated — the RED state is an emergency.
Source: Notes, ch. 15 — Performance and troubleshooting
Shortcuts: Enter reveals the answer or the options, then goes to the next one · 1–4 answers · Z undoes · E writes · Esc leaves the text box
Transparency note AI was used in this post for: generating the study questions · creating the English version