What is the difference between text and keyword field types?
Answer
The text field type is analyzed — the stored value is run through an analyzer to produce tokens for the inverted index, enabling full-text search with relevance scoring. Text fields cannot be used for sorting or aggregations (without a sub-field). The keyword field type is NOT analyzed — the value is stored as-is for exact matching. Keyword fields support sorting, aggregations (e.g., terms aggregation), and filtering. For a field like "product name" where you want both full-text search and the ability to aggregate or sort, use a multi-field mapping: {"type": "text", "fields": {"keyword": {"type": "keyword"}}} — this is the default for dynamic string mapping.
Previous
What are aggregations in Elasticsearch?
Next
What are index templates and component templates in Elasticsearch?
More Elasticsearch Questions
View all →- Intermediate What is the difference between query context and filter context in Elasticsearch?
- Intermediate What is a bool query in Elasticsearch?
- Intermediate What are aggregations in Elasticsearch?
- Intermediate What are index templates and component templates in Elasticsearch?
- Intermediate What is the Reindex API and when would you use it?