When i search for document after index a document. It returns empty but it returns document with sleep of 2 seconds between creating and fetching

时间:2018-07-25 04:43:19

标签: python elasticsearch python-unittest elasticsearch-5 elasticsearch-aggregation

I am using Elasticsearch . I am trying to connect Elasticsearch with python.

I can create index with document. When i tried to fetch the same once successful creation done it returns empty.

If i make the code to sleep for 2 seconds after creating the data in Elasticsearch, then it returns actual data.

Is there any interval required to create and search the same data?

Sample code:

es_client.index(index=index_id, doc_type=doc_type, id=doc_id, body=body)

returns:
{'_index': 'account_001', '_type': 'UnitTest', '_id': '9f48ae128e4811e88c4b0242ac120013', '_version': 1, 'result': 'created', '_shards': {'total': 2, 'successful': 2, 'failed': 0}, 'created': True}

es_client.search(index=index_id, doc_type=doc_type, body=query, filter_path=filter_path)

returns {}