Last active
August 29, 2015 14:01
-
-
Save gnosek/585a6717c570f4217168 to your computer and use it in GitHub Desktop.
Dynamic ElasticSearch mappings
This file contains 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
MAPPING = { | |
'_default_': { | |
'_all': {'enabled': False}, | |
'dynamic_templates': [ | |
{ | |
'analyzed_body': { | |
'match': 'body', | |
'match_mapping_type': 'string', | |
'mapping': { | |
'type': 'string', | |
'index': 'analyzed', | |
} | |
} | |
}, | |
{ | |
'default_not_analyzed': { | |
'match': '*', | |
'match_mapping_type': 'string', | |
'mapping': { | |
'type': 'string', | |
'index': 'not_analyzed', | |
} | |
} | |
}, | |
] | |
} | |
} | |
_seen_indices = set() | |
def ensure_index(es_conn, index_format, now): | |
index = now.strftime(index_format) | |
if index in _seen_indices: | |
return index | |
_seen_indices.add(index) | |
es_conn.indices.create_index_if_missing(index, settings={'mappings': MAPPING}) | |
return index |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment