Proper mapping is key for efficient search.
Types¶
- text — full-text
- keyword — exact match, aggregations
- integer/float
- date
- nested
- geo_point
Mapping¶
PUT /articles
{
"mappings": {
"properties": {
"title": {"type":"text","analyzer":"english"},
"slug": {"type":"keyword"},
"tags": {"type":"keyword"},
"published_at": {"type":"date"}
}
}
}
Mapping Best Practices¶
When designing a mapping, always use the keyword type for fields you filter or aggregate on (tags, statuses, identifiers). Use the text type only for fields where you need full-text search. For fields like titles where you need both, use multi-field mapping with both text and keyword subtypes.
Watch out for mapping explosion — if you dynamically add hundreds of new fields, Elasticsearch will consume large amounts of memory on metadata. Set dynamic to strict or false for production indexes. For localized data, use an analyzer with the appropriate language stemmer and stop words, which significantly improves the relevance of search results.
Mapping = Foundation¶
Define explicitly. Dynamic = prototypes only.