Search code examples
elasticsearchelasticsearch-bulk-apielastic-rest-client

Is there a way to identify when the elastic _bulk API created a new index vs when it operated on an existing index?


I am using the Elasticsearch _bulk api to insert some data into the index.

However, what I observed is that, if an index does not exist, this API will first create an index with dynamic mappings and then index the document.

Is there a way to find out in the response when this happens? I know there is a field in the response called result which tells if a particular document was updated or created, but is there a way to find out something similar for the index itself.

I am basically trying to avoid the API from creating the index. If the index does not exist, I want to be able to be informed somehow, so that I can re-create an index with some specific mappings instead of the dynamic mappings.

I am new to Elastic so I do not know if there is any other API that can help me do this while also being performant. The service I use indexes documents in batches of 5000.


Solution

  • You should simply disable index auto creation by modifying the following cluster settings:

    PUT _cluster/settings
    {
      "persistent": {
        "action.auto_create_index": "false"
      }
    }
    

    After setting that, the bulk call will include a status: 400 for the bulk item that tries to create a new index, you can review which one it is and create the index accordingly with the right mapping.