question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AttributeError: 'Search' object has no attribute 'delete'

See original GitHub issue

`from elasticsearch import Elasticsearch from elasticsearch_dsl import Search

client = Elasticsearch() s = Search(using=client) s = s.using(client) s = Search().using(client).query(“match”, title=“python”) response = s.execute() for hit in s: print(hit.title)

response = s.delete()`

after executing this code i have got the error AttributeError: ‘Search’ object has no attribute ‘delete’

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
WisdomPillcommented, Jan 24, 2018

There are some errors in your code. First you’re repeating yourself with all the using client, therefore I would suggest to you to use configure connections method for that so you don’t always specify the client on each search object. Regardless, the first attempt should work. Then you’re trying to delete a response which is not possible, you have to call a delete request on the query like you would do with the rest APIs of elasticsearch. After that you’re iterating s ichi is the search object and not the response. I have adjusted your code for different purposes since I don’t know what you were trying to do and I modified the query in a more dsl way.

from elasticsearch_dsl import Search
from elasticsearch_dsl.connections import connections
from elasticsearch_dsl.query import Match

conf = {
    'default': {
        'hosts': [
            {
                'host': 'localhost',
                'port': 9200
            }
        ]
    }
}

connections.configure(**conf)

# elasticsearch dsl python falls back to the default connection by default if you don't specify it in the search object

# simple search with iteration over the results
s = Search(index='your index name').query(Match(title='Python'))
r = s.execute()

# check the query
print(s.to_dict())

# iterate over results
for hit in r.hits:
    print(hit.to_dict())

# delete by query
s = Search(index='your index name').query(Match(title='Python'))
s.delete()

1reaction
honzakralcommented, Jan 24, 2018

@roshnikasliwal can you also specify which version of elasticsearch-dsl you are using? Search.delete() was added in 5.2. Thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError: 'Key' object has no attribute 'delete'
According to the source code of the library, you can use the delete function for that purpose: it accepts the key of the...
Read more >
object has no attribute 'delete' - Google Groups
Hi all,. I'm trying migrate from 0.3 to 0.6. I don't know how to delete an object. in the old version it was:...
Read more >
AttributeError at /map/ 'NoneType' object has no attribute 'delete'
Hi, inside my urls.py file I have the following code: from django.urls import path from . import views urlpatterns = [ path('map/', views....
Read more >
AttributeError: 'str' object has no attribute 'remove' | bobbyhadz
The Python "AttributeError: 'str' object has no attribute 'remove'" occurs when we try to call the remove() method on a string instead of...
Read more >
Search DSL — Elasticsearch DSL 7.2.0 documentation
You can delete the documents matching a search by calling delete on the Search object ... If you already have a query object,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found