feat: 新增 core.search.es
This commit is contained in:
0
nc_http/core/search/es/__init__.py
Normal file
0
nc_http/core/search/es/__init__.py
Normal file
25
nc_http/core/search/es/func.py
Normal file
25
nc_http/core/search/es/func.py
Normal 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)
|
Reference in New Issue
Block a user