Elasticsearch dsl删除错误
Elasticsearch dsl deleting error
我在使用 elasticsearch dsl 删除项目时遇到问题。当我尝试过滤我的数据时,它很容易进行,而且这样的东西效果很好。
def searchId(fileId):
s = Search().filter('term', fileId=fileId)
# for hit in s:
# print(str(hit.foreignKey))
response=s.execute()
# print(response.hits.total)
return response
扫描也有效:
def scanning():
s = Search()
i = 0
for hit in s.scan():
if hit.domain == 'Messages':
i+=1
print(str(hit.fileId) + " : " + str(hit.domain) + " : " + str(i))
但是当我想删除这样的项目时:
def deleteId(fileId):
s = Search().query('match', fileId=fileId)
response = s.delete()
return "Done"
我收到一个错误:
Traceback (most recent call last):
File "", line 1, in
File "/home/o.solop/DataSearchEngine/datasearch/elasticapp/search.py", line 96, in deleteId
response = s.delete()
File "/usr/local/lib/python2.7/dist-packages/elasticsearch_dsl/search.py", line 660, in delete
**self._params
File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/utils.py", line 73, in _wrapped
return func(*args, params=params, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/__init__.py", line 887, in delete_by_query
raise ValueError("Empty value passed for a required argument.")
ValueError: Empty value passed for a required argument.
我在搜索构造函数中遗漏了一个索引。我应该这样做:
def deleteId(fileId):
s = Search(index='my_index_name').query('match', fileId=fileId)
response = s.delete()
Elasticsearch-dsl
使用 delete_by_query API,如我的错误消息所示,它需要知道要针对哪个索引执行删除。
我在使用 elasticsearch dsl 删除项目时遇到问题。当我尝试过滤我的数据时,它很容易进行,而且这样的东西效果很好。
def searchId(fileId):
s = Search().filter('term', fileId=fileId)
# for hit in s:
# print(str(hit.foreignKey))
response=s.execute()
# print(response.hits.total)
return response
扫描也有效:
def scanning():
s = Search()
i = 0
for hit in s.scan():
if hit.domain == 'Messages':
i+=1
print(str(hit.fileId) + " : " + str(hit.domain) + " : " + str(i))
但是当我想删除这样的项目时:
def deleteId(fileId):
s = Search().query('match', fileId=fileId)
response = s.delete()
return "Done"
我收到一个错误:
Traceback (most recent call last): File "", line 1, in File "/home/o.solop/DataSearchEngine/datasearch/elasticapp/search.py", line 96, in deleteId response = s.delete() File "/usr/local/lib/python2.7/dist-packages/elasticsearch_dsl/search.py", line 660, in delete **self._params File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/utils.py", line 73, in _wrapped return func(*args, params=params, **kwargs) File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/__init__.py", line 887, in delete_by_query raise ValueError("Empty value passed for a required argument.") ValueError: Empty value passed for a required argument.
我在搜索构造函数中遗漏了一个索引。我应该这样做:
def deleteId(fileId):
s = Search(index='my_index_name').query('match', fileId=fileId)
response = s.delete()
Elasticsearch-dsl
使用 delete_by_query API,如我的错误消息所示,它需要知道要针对哪个索引执行删除。