1

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?

Dimitris
  • 2,030
  • 3
  • 27
  • 45
  • What do you mean by "debug mode"? – MrName Aug 16 '17 at 22:10
  • I am using VS Code and debugging this. If I am in Debug mode then it works. If I run python then it's not. Really strange – Dimitris Aug 16 '17 at 22:24
  • I don't really know much about that IDE, but is it possible that your connection definition is somehow set in your IDE? It might be worth stepping through this on the console with `pdb`. – MrName Aug 16 '17 at 23:29

2 Answers2

2

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’

0

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.

Dimitris
  • 2,030
  • 3
  • 27
  • 45