Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have a problem with deleting items using elasticsearch dsl. When i trying to filter my data it goes easily and something like this works great.

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

Scanning works also :

def scanning():
s = Search()
i = 0
for hit in s.scan():
    if hit.domain == 'Messages':
        print(str(hit.fileId) + " : " + str(hit.domain) + " : " + str(i))

But when i wanna to delete items like this :

def deleteId(fileId):
s = Search().query('match', fileId=fileId)
response = s.delete()
return "Done"

I got an error :

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.

I missed an index in the Search constructor. I should do something like:

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

Elasticsearch-dsl uses the delete_by_query API, as indicated in my error message, which needs to know which index to perform the delete against.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.