Given the following mapping and query, what will be the result count?
{
"mappings": {
"properties": {
"name": { "type": "text" },
"category": { "type": "keyword" }
}
}
}
POST /products/_search
{
"query": {
"term": { "category": "electronics" }
}
}Remember that keyword fields are not analyzed and match exact values.
The term query matches exact values on keyword fields. Since category is a keyword field, it matches documents where the category is exactly 'electronics'.
Which reason best explains why you would choose text type over keyword type for a field in Elasticsearch?
Think about when you want to search inside the text rather than match exact values.
The text type is used for full-text search. It breaks the text into tokens and applies analysis, allowing searches for words inside the text. The keyword type stores exact values without analysis.
Given this mapping and query, why does the term query return zero results?
{
"mappings": {
"properties": {
"description": { "type": "text" }
}
}
}
POST /items/_search
{
"query": {
"term": { "description": "fast car" }
}
}Think about how term queries work on text fields.
Term queries look for exact matches. Since 'description' is a text field, it is analyzed and broken into tokens like 'fast' and 'car'. The term query with 'fast car' as a whole string does not match any token exactly, so it returns zero results.
Choose the correct mapping snippet that allows a field to be searched as full text and also filtered exactly.
Think about multi-fields and how to support both search and filtering.
Option A defines a text field for full-text search and a subfield raw of type keyword for exact filtering and sorting. This is the recommended pattern.
In Elasticsearch, what is the practical limit on the number of unique values in a keyword field before performance degrades significantly?
Consider how Elasticsearch stores keyword terms and the impact on memory.
Keyword fields store terms in memory for filtering and aggregations. Having too many unique values (cardinality) can cause memory and performance issues. Usually, a few thousand unique values is manageable.