(send_data) Script set settings: replicas at 0
This commit is contained in:
23
send_data.py
23
send_data.py
@@ -65,6 +65,8 @@ def put_mapping(index_name, mapping_file, quiet=False):
|
|||||||
if not quiet:
|
if not quiet:
|
||||||
print("File '{} sended to Elasticsearch!".format(mapping_file.name))
|
print("File '{} sended to Elasticsearch!".format(mapping_file.name))
|
||||||
|
|
||||||
|
put_setting(index_name, quiet)
|
||||||
|
|
||||||
def check_all_data_is_saved(file):
|
def check_all_data_is_saved(file):
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
with open(file.name, 'r') as file:
|
with open(file.name, 'r') as file:
|
||||||
@@ -73,10 +75,10 @@ def check_all_data_is_saved(file):
|
|||||||
extract = json.loads(lines[1])
|
extract = json.loads(lines[1])
|
||||||
type = extract['type']
|
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',
|
res = requests.get(url=ELASTICSEARCH_URL + INDEX_NAME + '/_search?size=0',
|
||||||
data=payload,
|
data=json.dumps(payload),
|
||||||
headers={'Content-Type': 'application/x-ndjson'})
|
headers={'Content-Type': 'application/x-ndjson'})
|
||||||
|
|
||||||
element_in_els = res.json()['hits']['total']['value']
|
element_in_els = res.json()['hits']['total']['value']
|
||||||
@@ -84,6 +86,23 @@ def check_all_data_is_saved(file):
|
|||||||
print(element_in_els)
|
print(element_in_els)
|
||||||
print(str(int(file_nb_line)))
|
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 ####
|
#### main block ####
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user