Skip to content

Instantly share code, notes, and snippets.

@adngdb
Created July 19, 2017 17:06
Show Gist options
  • Save adngdb/fd30965ce5c1e5523f2880d9a33dad20 to your computer and use it in GitHub Desktop.
Save adngdb/fd30965ce5c1e5523f2880d9a33dad20 to your computer and use it in GitHub Desktop.
Create Elasticsearch index and print mapping
import json
from configman import Namespace
from configman.converters import class_converter
from socorro.app import generic_app
from socorro.external.es.super_search_fields import (
SuperSearchFields
)
class CreateIndexApp(generic_app.App):
required_config = Namespace()
required_config.namespace('elasticsearch')
required_config.elasticsearch.add_option(
'elasticsearch_class',
default='socorro.external.es.connection_context.ConnectionContext',
from_string_converter=class_converter,
)
required_config.elasticsearch.add_option(
'index_creator_class',
default='socorro.external.es.index_creator.IndexCreator',
from_string_converter=class_converter,
)
def main(self):
index_creator = self.config.elasticsearch.index_creator_class(
self.config.elasticsearch
)
mappings = SuperSearchFields(config=self.config).get_mapping()
es_settings = index_creator.get_socorro_index_settings(mappings)
print(json.dumps(es_settings, indent=4))
try:
index_creator.create_socorro_index('test_index')
except Exception as e:
print(str(e))
return
index_creator.get_index_client().delete('test_index')
if __name__ == '__main__':
generic_app.main(CreateIndexApp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment