diff --git a/nc_http/core/search/es/__init__.py b/nc_http/core/search/es/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nc_http/core/search/es.py b/nc_http/core/search/es/elastic_base.py similarity index 100% rename from nc_http/core/search/es.py rename to nc_http/core/search/es/elastic_base.py diff --git a/nc_http/core/search/es/func.py b/nc_http/core/search/es/func.py new file mode 100644 index 0000000..51e31fe --- /dev/null +++ b/nc_http/core/search/es/func.py @@ -0,0 +1,25 @@ +import json + +import requests +from elasticsearch_dsl import connections + + +def clean_es(host, index_name, type_=None): + """ + 清空 es + :param host: + :param index_name: + :param type_: + :return: + """ + connections.create_connection(hosts=[host]) + headers = {'Content-Type': 'application/json'} + # 删除 index + url = '{}/{}/_delete_by_query'.format(host, index_name) + if not type_: + data = {"query": {"match_all": {}}} + else: + data = {"query": {"term": {"type": {"value": type_}}}} + result = requests.post(url, json.dumps(data), headers=headers) + r = json.loads(result.content) + print(r)