Reputation: 2036
I am using the elasticsearch-dsl package in Python for my project. I have a very simple search query as can be seen below:
s = Search(using=connections.get_connection(), index= 'registry', doc_type=['storage_doc']).params(request_timeout=60)
s.filter("match", postcode="SW1").query("match", forename="Brendan")
response = s.execute(ignore_cache=True)
print(response.success())
print(response.took)
print(response.to_dict())
print('Total %d hits found.' % response.hits.total)
which works fine if I execute it in debug mode but when I run the code from the console I always get 0 hits. I have no idea why this is happening and I have spent already half a day trying to find a solution. Any ideas?
Upvotes: 1
Views: 591
Reputation: 21
there is one argument in elastic "index" operation called "refresh" with three options. If you set refresh='true' then you will get response from index operation after elastic add data to index. From here: enter link description here
refresh – If true then refresh the affected shards to make this operation visible to search, if wait_for then wait for a refresh to make this operation visible to search, if false (the default) then do nothing with refreshes., valid choices are: ‘true’, ‘false’, ‘wait_for’
Upvotes: 2
Reputation: 2036
The problem was that the search was taking place immediately after indexing that test data. Potentially Elasticsearch didn't have enough time to index the data and search it and as a result I was getting zero hits. If indexing takes place at a different point in time with search then it all works as expected. This behaviour is a result purely of early tests that we are currently running.
Upvotes: 0