Elasticsearch & Lucene (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What is the difference between `text` and `keyword` data types?
junior LevelCode ExampleelasticsearchBasic
In Simple Words:
text: Analyzed and tokenized into individual terms. Used for full-text search (e.g. blog post bodies, product descriptions). Cannot be used for sorting or exact aggregation.keyword: Not analyzed; stored exactly as an unaltered string. Used for exact value lookups, filtering, sorting, and aggregations (e.g. email addresses, status codes, tags, UUIDs).
json
// Mapping definition with multi-fields:
{
"properties": {
"title": {
"type": "text",
"fields": {
"raw": { "type": "keyword" } // Allows both full-text search AND exact sorting!
}
}
}
}