【问题标题】:Elasticsearch dsl deleting errorElasticsearch dsl 删除错误
【发布时间】:2017-11-19 04:00:24
【问题描述】:

我在使用 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"

我遇到了一个错误:

回溯(最近一次通话最后): 文件“”,第 1 行,在 文件“/home/o.solop/DataSearchEngine/datasearch/elasticapp/search.py​​”,第 96 行,在 deleteId 响应 = s.delete() 文件“/usr/local/lib/python2.7/dist-packages/elasticsearch_dsl/search.py​​”,第 660 行,在删除 **self._params _wrapped 中的文件“/usr/local/lib/python2.7/dist-packages/elasticsearch/client/utils.py”,第 73 行 返回函数(*args,参数=参数,**kwargs) 文件“/usr/local/lib/python2.7/dist-packages/elasticsearch/client/__init__.py”,第 887 行,在 delete_by_query raise ValueError("为所需参数传递的空值。") ValueError:为所需参数传递的空值。

【问题讨论】:

    标签: python django elasticsearch-dsl


    【解决方案1】:

    我错过了 Search 构造函数中的索引。我应该这样做:

    def deleteId(fileId):
     s = Search(index='my_index_name').query('match', fileId=fileId)
     response = s.delete()
    

    Elasticsearch-dsl 使用 delete_by_query API,如我的错误消息中所示,它需要知道要针对哪个索引执行删除。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-16
      • 2017-05-20
      • 2021-06-09
      • 1970-01-01
      • 1970-01-01
      • 2018-10-11
      • 2016-06-23
      相关资源
      最近更新 更多