Elasticsearch interview questions

25 questions from the Elasticsearch course, each with the correct answer and an explanation. Try to answer before you open the answer.

Elasticsearch Foundations

1. Which library provides the core indexing and scoring inside Elasticsearch?

  1. RocksDB
  2. Apache Kafka
  3. Apache Lucene
  4. Apache Spark
Show answer

Answer: Apache Lucene

Each Elasticsearch shard is a Lucene index.

Lesson: What Elasticsearch Is

2. What does an inverted index map?

  1. Each term to the documents that contain it
  2. Each document to its storage address only
  3. Each shard to a node
  4. Each user to their permissions
Show answer

Answer: Each term to the documents that contain it

Looking up a term returns its postings list directly.

Lesson: The Inverted Index

3. Which index setting can be changed on a live index without reindexing?

  1. The index name
  2. number_of_shards
  3. The type of an existing field
  4. number_of_replicas
Show answer

Answer: number_of_replicas

Replica count is dynamic; primary count is fixed at creation.

Lesson: Cluster, Node, Index, Shard and Replica

Indexing and Mappings

4. What format does the bulk API body use?

  1. A single JSON array of documents
  2. Newline-delimited JSON with action and source lines
  3. CSV with a header row
  4. XML with one element per document
Show answer

Answer: Newline-delimited JSON with action and source lines

NDJSON lets the coordinating node split the request without parsing it as one big document.

Lesson: Document CRUD and the Bulk API

5. Which field type fits a status value used for exact filters and terms aggregations?

  1. text
  2. keyword
  3. nested
  4. dense_vector
Show answer

Answer: keyword

keyword stores the exact value and supports aggregations via doc values.

Lesson: Field Types: text, keyword and Friends

6. You need to change an existing field from text to keyword. What is required?

  1. Clear the cache
  2. Send PUT _mapping with the new type
  3. Restart the cluster
  4. Create a new index with the new mapping and reindex the data
Show answer

Answer: Create a new index with the new mapping and reindex the data

Existing field types cannot be changed in place.

Lesson: Dynamic Mapping Pitfalls and Explicit Mappings

Text Analysis

7. How many tokenizers does an analyzer have?

  1. Exactly one
  2. Zero or more
  3. At least two
  4. One per token filter
Show answer

Answer: Exactly one

Character and token filters are optional and can be many; the tokenizer is required and single.

Lesson: How Analyzers Work

8. Why are synonyms often applied only in the search analyzer?

  1. It makes indexing slower
  2. Index-time synonyms are not supported
  3. The synonym list can be updated without reindexing documents
  4. Search analyzers cannot stem
Show answer

Answer: The synonym list can be updated without reindexing documents

Search-time synonyms change queries, not stored terms.

Lesson: Custom Analyzers: Synonyms, Stemming and Folding

9. A match query fails to find a document. What is a good first debugging step?

  1. Switch the field to dense_vector
  2. Increase the number of shards
  3. Run _analyze on both the document text and the query text with the field's analyzers
  4. Restart the node
Show answer

Answer: Run _analyze on both the document text and the query text with the field's analyzers

Comparing produced terms reveals analysis mismatches.

Lesson: Debugging With the _analyze API

The Query DSL

10. Which query requires its terms to appear in order and near each other?

  1. match_phrase
  2. match with operator or
  3. term
  4. exists
Show answer

Answer: match_phrase

match_phrase uses term positions; slop relaxes adjacency.

Lesson: Full-Text Queries: match, multi_match, match_phrase

11. Where should an exact condition like tenant_id = 42 go in a bool query?

  1. In a function_score weight
  2. In must, using a match query
  3. In should, so it can be skipped
  4. In filter, using a term query
Show answer

Answer: In filter, using a term query

Filter context is exact, unscored and cacheable.

Lesson: The bool Query and Term-Level Queries

12. Under BM25, which term contributes more to the score, all else equal?

  1. A term that appears in every document
  2. A term that is rare across the index
  3. A term in a much longer field
  4. A term only in a filter clause
Show answer

Answer: A term that is rare across the index

Inverse document frequency rewards rare terms; filters do not score.

Lesson: Relevance: BM25, Boosting and function_score

Aggregations

13. Why can terms aggregation counts be approximate?

  1. Elasticsearch samples 1% of documents
  2. Each shard returns only its own top terms before results are merged
  3. Counts are rounded to tens
  4. Replicas return stale counts
Show answer

Answer: Each shard returns only its own top terms before results are merged

shard_size and doc_count_error_upper_bound address this.

Lesson: Bucket Aggregations: terms, date_histogram, range

14. What does the cardinality aggregation return?

  1. The number of shards
  2. The exact number of documents
  3. The largest value in a field
  4. An approximate count of distinct values
Show answer

Answer: An approximate count of distinct values

It uses HyperLogLog++ with a precision_threshold.

Lesson: Metric Aggregations: avg, percentiles, cardinality

15. What does post_filter change?

  1. Only the returned hits, not the aggregations
  2. Only the aggregations, not the hits
  3. Both hits and aggregations equally
  4. The relevance scores of hits
Show answer

Answer: Only the returned hits, not the aggregations

Aggregations are computed before post_filter is applied.

Lesson: Faceted Search With post_filter

Search Features

16. What is the recommended way to page deeply through results?

  1. Raising max_result_window to millions
  2. from and size with a large from
  3. search_after with a point in time
  4. One query per shard
Show answer

Answer: search_after with a point in time

It avoids collecting from + size hits on every shard.

Lesson: Pagination: from/size, search_after and Point in Time

17. How is a search_as_you_type field usually queried?

  1. A cardinality aggregation
  2. A term query on the root field
  3. multi_match with type bool_prefix over the field and its n-gram sub-fields
  4. A match_phrase with slop 100
Show answer

Answer: multi_match with type bool_prefix over the field and its n-gram sub-fields

bool_prefix treats the last term as a prefix.

Lesson: Highlighting and Autocomplete

18. What does increasing num_candidates in a knn search generally do?

  1. Improves recall at the cost of more work per shard
  2. Changes the vector dimensions
  3. Disables filters
  4. Switches scoring to BM25
Show answer

Answer: Improves recall at the cost of more work per shard

More candidates are explored in the HNSW graph.

Lesson: Vector Search and Hybrid Retrieval

Operating a Cluster

19. A single-node cluster with replicas set to 1 is usually what colour?

  1. Blue
  2. Green
  3. Red
  4. Yellow, because replicas cannot be placed on the node holding the primary
Show answer

Answer: Yellow, because replicas cannot be placed on the node holding the primary

All primaries are assigned but replicas are not.

Lesson: Cluster Health, Shard Sizing and Replicas

20. Which field must every document in a data stream have?

  1. _routing
  2. @timestamp
  3. id
  4. version
Show answer

Answer: @timestamp

Data streams are designed for time-series, append-only data.

Lesson: Aliases, ILM and Data Streams

21. Why is the alias switch done in a single _aliases request?

  1. It is faster to type
  2. The remove and add actions apply atomically, so clients never see no index
  3. Aliases can only be changed once
  4. It triggers an automatic reindex
Show answer

Answer: The remove and add actions apply atomically, so clients never see no index

Atomic alias updates make the cutover seamless.

Lesson: Reindex and Zero-Downtime Mapping Changes

Elasticsearch in Production

22. Which change typically speeds up a large one-off bulk load?

  1. Running every condition in must instead of filter
  2. Using one document per request
  3. Setting refresh_interval to 1ms
  4. Disabling refresh and replicas during the load, then restoring them
Show answer

Answer: Disabling refresh and replicas during the load, then restoring them

Fewer refreshes and no replication during the load reduce work.

Lesson: Performance Tuning

23. How should a public web app let users search Elasticsearch?

  1. Through a backend that builds queries and calls a private cluster with a least-privilege API key
  2. By exposing port 9200 to browsers
  3. By embedding the elastic superuser password in JavaScript
  4. By disabling security for read requests
Show answer

Answer: Through a backend that builds queries and calls a private cluster with a least-privilege API key

Keep the cluster private and the credentials server-side.

Lesson: Security

24. What is the main weakness of dual writes from application code?

  1. It requires Kafka
  2. Elasticsearch cannot accept writes from applications
  3. A failure between the two writes leaves the database and the index inconsistent
  4. It makes documents immutable
Show answer

Answer: A failure between the two writes leaves the database and the index inconsistent

Outbox or CDC ties index updates to committed database changes.

Lesson: Keeping Elasticsearch in Sync With the Database

25. Which item belongs on an Elasticsearch production checklist?

  1. Rely on dynamic mapping for all fields
  2. Expose the cluster publicly for easier debugging
  3. Applications access indices through aliases so reindexing does not need downtime
  4. Use from/size for exports of millions of documents
Show answer

Answer: Applications access indices through aliases so reindexing does not need downtime

Aliases make migrations routine.

Lesson: An Elasticsearch Production Checklist

← Back to the course