Elasticsearch medium
An application queries a `text` field for 'Apple' using a `term` query but receives 0 results, despite the word existing in the document. What is the technical reason?
- A The `term` query is case-sensitive and performs an exact byte-match against the inverted index. The standard analyzer lower-cased 'Apple' to 'apple' during indexing, making a match impossible.
- B The `term` query only works on numeric and date fields.
- C The coordinating node has not yet performed a 'Global Refresh' for that specific shard.
- D The `text` field mapping defaults to 'lazy' evaluation, requiring a `match` query to wake it up.
Answer: A. The `term` query is case-sensitive and performs an exact byte-match against the inverted index. The standard analyzer lower-cased 'Apple' to 'apple' during indexing, making a match impossible.
This is a fundamental distinction. `term` queries are for exact values (e.g., IDs, statuses). `match` queries use the same analyzer as the field, transforming 'Apple' into 'apple' before searching, ensuring it finds the analyzed tokens in the index.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- What are the two primary reasons for configuring one or more 'Replica Shards' for an index?
- When a String field is mapped as `text`, what process is performed to enable full-text search capability?
- What is the primary benefit of splitting an Elasticsearch index into multiple 'Primary Shards'?
- Every document stored in an Elasticsearch index is uniquely tracked by which mandatory metadata field?
- Elasticsearch search results include a metadata field called `_score`. What does this value primarily indicate?
- What is the primary architectural purpose of Elasticsearch in a modern software stack?