Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Elasticsearch mapping with dynamic templates for customer attributes
{
"template": "account-*",
"settings": {
"analysis": {
"analyzer": {
"default": {
"tokenizer": "keyword",
"filter": "lowercase"
}
}
}
},
"mappings": {
"contact": {
"properties": {
},
"dynamic_templates": [{
"long_to_integers": {
"match_mapping_type": "long",
"mapping": {
"type": "integer"
}
}
}, {
"double_to_integers": {
"match_mapping_type": "double",
"mapping": {
"type": "integer"
}
}
}, {
"float_to_integers": {
"match_mapping_type": "float",
"mapping": {
"type": "integer"
}
}
}, {
"strings_to_texts": {
"match_mapping_type": "string",
"mapping": {
"type": "text"
}
}
}, {
"fields_ending_in_at_as_dates": {
"match_mapping_type": "string",
"match": "*_at",
"mapping": {
"type": "date"
}
}
}, {
"fields_ending_in_count_as_integers": {
"match_mapping_type": "long",
"match": "*_count",
"mapping": {
"type": "integer"
}
}
}]
}
}
}
@lcpriest

This comment has been minimized.

Copy link
Owner Author

@lcpriest lcpriest commented Mar 22, 2017

I use this template for a multi-tenanted elasticsearch instance with one index per account.
Each account pulls data from multiple sources and can have any manner of attributes.

Things to note:

I don't care too much about exact replicas of the data - it is stored in Postgres and this is just used for search. To that end, I very aggressively coerce floats, doubles and longs into integers.

All matches are done on the lowercased term, with none of the ES magic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.