Last active
October 10, 2018 01:23
-
-
Save LimaGuilherme/9060754fc6b3a62d2169a561b00ae56c to your computer and use it in GitHub Desktop.
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
| import elasticsearch | |
| import elasticsearch_dsl | |
| from elasticsearch_dsl.connections import connections, get_connection | |
| import config as config_module | |
| config = config_module.get_config() | |
| connections.create_connection( | |
| hosts=[{'host': 'localhost', 'port': 9200}], | |
| use_ssl=False, | |
| verify_certs=False, | |
| connection_class=elasticsearch.RequestsHttpConnection | |
| ) | |
| class Country(elasticsearch_dsl.DocType): | |
| country = elasticsearch_dsl.Text() | |
| state = elasticsearch_dsl.Text() | |
| shape = elasticsearch_dsl.GeoShape(required=True, tree='quadtree', precision='5km') | |
| class Meta: | |
| doc_type = '_doc' | |
| index = 'countries' | |
| @classmethod | |
| def index_country(cls, **kwargs): | |
| country = cls(**kwargs) | |
| try: | |
| country.save() | |
| except elasticsearch.TransportError as ex: | |
| return ex.message | |
| except Exception as ex: | |
| print(ex.message) | |
| return municipio |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment