Skip to content

Instantly share code, notes, and snippets.

@LimaGuilherme
Last active October 10, 2018 01:23
Show Gist options
  • Select an option

  • Save LimaGuilherme/9060754fc6b3a62d2169a561b00ae56c to your computer and use it in GitHub Desktop.

Select an option

Save LimaGuilherme/9060754fc6b3a62d2169a561b00ae56c to your computer and use it in GitHub Desktop.
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