Query DSLmedium3-5 years
A `bool` query's `filter` array has `{ "term": { "title": "Kafka" } }`, where `title` is mapped as `text` with the standard analyser. It matches nothing, even for documents whose title is literally "Kafka". Diagnose it, and name the two different fixes depending on what the query actually needs to do.
term matches an exact, unanalysed string against the exact terms in the index. title as a text field was analysed at index time — the standard analyser at minimum lowercases, so "Kafka" was indexed as the term kafka, not Kafka. The term query for "Kafka" (capitalized) never matches the indexed lowercase term. Two different fixes depending on intent: if the goal is full-text matching (find documents whose title contains the word, case-insensitively, contributing to relevance), use match instead of term, which analyses the query text too. If the goal is an exact-value filter (title equals this precise string, no analysis, no scoring), query the title.keyword sub-field instead, which dynamic mapping created and stores the value unanalysed.
PreviousA product search puts `{ "term": { "status": "PUBLISHED" } }` inside a `bool` query's `must` clause alongside the user's search text. What's wasted by doing that, and what's the fix?Next A team wants to add primary shards to an existing, growing index without reindexing, expecting it to rebalance data across the new shards the way adding a database read replica doesn't require touching existing data. Why doesn't this work, and what's the actual mechanism that makes the primary shard count permanent?