feat: 新增 core.search.es

This commit is contained in:
han0
2023-03-17 15:06:17 +08:00
parent 3deb269adc
commit 6f004e73fd
3 changed files with 25 additions and 0 deletions

View File

View File

@@ -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)