Create an index if not exist and add a document to it

I tried to dynamically create an index (if not exist) with static mapping, then added a document to it immediately. After that, I checked mapping of the index and found that the mapping is not what I described in request. It seems that mapping is dynamically created according to the fields of the document.
But if the document is added in seconds after index created, everything works as expected.
My question is:

  1. Is the API of creating index asynchronous and I should wait util index created before adding document?
  2. If not, what is the correct way to achieve "create an index if not exist and add a document to it"?

Can you share the JSON you used to create the mapping to others can take a look? Also which Elasticsearch version are you using?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.