Created
March 22, 2017 09:20
-
-
Save lcpriest/e9c154034262c42867c15358ded0001a to your computer and use it in GitHub Desktop.
Elasticsearch mapping with dynamic templates for customer attributes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} | |
}] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.