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.