ElasticSearch host and port are taken for ENV_VAR, so that we can run ElasticSearch in a remote machine
This commit is contained in:
parent
ea91a6a0e0
commit
2ff897622c
|
@ -45,7 +45,7 @@ class CadasterEntry:
|
|||
|
||||
def to_elasticsearch(self):
|
||||
""" Gets stored in elastic search """
|
||||
es = Elasticsearch()
|
||||
es = Elasticsearch(hosts=[config['elasticsearch-host']], port=config['elasticsearch-port'])
|
||||
res = None
|
||||
try:
|
||||
body = json.dumps(self.to_json(), cls=JSONEncoder,sort_keys=True,
|
||||
|
@ -61,7 +61,7 @@ class CadasterEntry:
|
|||
def from_elasticsearch(self):
|
||||
""" Confirms for checking purposes that the entry has been stored in elastic search previously """
|
||||
res = False
|
||||
es = Elasticsearch()
|
||||
es = Elasticsearch(hosts=[config['elasticsearch-host']], port=config['elasticsearch-port'])
|
||||
try:
|
||||
query = '{"query":{"bool":{"must":[{"match":{"cadaster":"' + self.cadaster + '"}}],"must_not":[],"should":[]}},"from":0,"size":10,"sort":[],"aggs":{}}'
|
||||
res = es.search(index=config['elasticsearch-index'], body=query)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
from os import environ
|
||||
|
||||
""" Dict settings file with config parameters"""
|
||||
|
||||
|
@ -20,6 +21,8 @@ config = {
|
|||
"sleep_dos_time": 300,
|
||||
"width_px": 120,
|
||||
"height_px": 120,
|
||||
"elasticsearch-host": environ.get('ES_HOST') if environ.get('ES_HOST') is not None else "localhost",
|
||||
"elasticsearch-port": environ.get('ES_PORT') if environ.get('ES_PORT') is not None else "9200",
|
||||
"servers_down_message_001": "Error 001: Cadastro server to get provinces and cities is down.\n"
|
||||
"Consequence: Search by provinces will fail.\n"
|
||||
"Maintenance is usually carried out durign the night or the weekends. Please, retry later.\n"
|
||||
|
|
|
@ -22,7 +22,7 @@ class ElasticSearchUtils:
|
|||
Creates index in ElasticSearch
|
||||
"""
|
||||
ElasticSearchUtils.remove_index()
|
||||
es = Elasticsearch()
|
||||
es = Elasticsearch(hosts=[config['elasticsearch-host']], port=config['elasticsearch-port'])
|
||||
request_body = {
|
||||
"settings": {
|
||||
"number_of_shards": 5,
|
||||
|
@ -87,7 +87,7 @@ class ElasticSearchUtils:
|
|||
"""
|
||||
Removes index from ElasticSearch
|
||||
"""
|
||||
es = Elasticsearch()
|
||||
es = Elasticsearch(hosts=[config['elasticsearch-host']], port=config['elasticsearch-port'])
|
||||
logger.debug("Deleting 'cadaster' index...")
|
||||
try:
|
||||
res = es.indices.delete(index='cadaster', ignore=[400, 404])
|
||||
|
@ -121,7 +121,7 @@ class ElasticSearchUtils:
|
|||
"size":11,
|
||||
"sort":[],
|
||||
"aggs":{}}
|
||||
es = Elasticsearch()
|
||||
es = Elasticsearch(hosts=[config['elasticsearch-host']], port=config['elasticsearch-port'])
|
||||
try:
|
||||
res = es.search(config['elasticsearch-index'], config['elasticsearch-doc'], query)
|
||||
hits = DotMap(res).hits.total
|
||||
|
|
Loading…
Reference in New Issue