I run a search right after ingesting documents through my Python client and get an empty response even though in Kibana I can see that everything is ingested correctly. Here's a simple demo code:
from elasticsearch import Elasticsearch, helpers
es_host = 'localhost'
es_port = '9200'
es = Elasticsearch([{'host': es_host, 'port': es_port}])
bulk_data = []
for i in range(5):
obj = {}
obj['_index'] = 'test_ind'
obj['_type'] = 'my_type'
obj['a'] = i
bulk_data.append(obj)
bulk_data = iter(bulk_data)
helpers.bulk(es, bulk_data)
body = {
"query": {
"match_all": {}
}
}
print es.search('test_ind', body)
The above code does the ingestion but the search returns nothing. However, when I run my search in a separate code, it works as expected.
from elasticsearch import Elasticsearch
es_host = 'localhost'
es_port = '9200'
es = Elasticsearch([{'host': es_host, 'port': es_port}])
body = {
"query": {
"match_all": {}
}
}
print es.search('test_ind', body=body)
Is there a conceptual reason as to why the first approach won't work or is this just a newbie goof on my part?
PS. Not sure if this matters but I'm using Python 2.7 and Elastic 5.5 (I know!!).