(send_data) Script set settings: replicas at 0
This commit is contained in:
25
send_data.py
25
send_data.py
@@ -65,6 +65,8 @@ def put_mapping(index_name, mapping_file, quiet=False):
|
||||
if not quiet:
|
||||
print("File '{} sended to Elasticsearch!".format(mapping_file.name))
|
||||
|
||||
put_setting(index_name, quiet)
|
||||
|
||||
def check_all_data_is_saved(file):
|
||||
time.sleep(2)
|
||||
with open(file.name, 'r') as file:
|
||||
@@ -73,17 +75,34 @@ def check_all_data_is_saved(file):
|
||||
extract = json.loads(lines[1])
|
||||
type = extract['type']
|
||||
|
||||
payload = "{\"track_total_hits\": true,\"query\": {\"constant_score\": {\"filter\": {\"term\": {\"type\": \""+ type + "\"}}}}}"
|
||||
payload = {"track_total_hits": "true", "query": {"constant_score": {"filter": {"term": {"type": type}}}}}
|
||||
|
||||
res = requests.get(url=ELASTICSEARCH_URL + INDEX_NAME + '/_search?size=0',
|
||||
data=payload,
|
||||
headers={'Content-Type': 'application/x-ndjson'})
|
||||
data=json.dumps(payload),
|
||||
headers={'Content-Type': 'application/x-ndjson'})
|
||||
|
||||
element_in_els = res.json()['hits']['total']['value']
|
||||
|
||||
print(element_in_els)
|
||||
print(str(int(file_nb_line)))
|
||||
|
||||
def put_setting(index_name, quiet=False):
|
||||
"""
|
||||
Update setting of index to set number of replica to 0
|
||||
"""
|
||||
if not quiet:
|
||||
print("Update setting of index '{}' - set replica to 0...".format(index_name))
|
||||
|
||||
query = {"index" : {"number_of_replicas" : 0}}
|
||||
res = requests.put(url=ELASTICSEARCH_URL + index_name + "/_settings",
|
||||
data=json.dumps(query),
|
||||
headers={'Content-Type': 'application/json'})
|
||||
if res.status_code != 200:
|
||||
print("An error occured")
|
||||
print(res.text)
|
||||
else:
|
||||
if not quiet:
|
||||
print('Setting of index updated')
|
||||
|
||||
#### main block ####
|
||||
|
||||
|
||||
Reference in New Issue
Block a user