Search code examples
elasticsearchbulkinsertelasticsearch-py

Bulk updating without type using elastic search py


I'm trying to do a bulk insert using elastic search py, but I don't want to specify a type, but it won't allow me to specify None or "" for the value of type. How can I get around this?

bulk_data = []

this_merchant_product = {'field1': 'value1'}

op_dict = {
    "index": {
        "_index": "product",
        "_type": None,
        "_id": str(this_merchant_product_id)
    }
}

bulk_data.append(op_dict)
bulk_data.append(this_merchant_product)

es = Elasticsearch()
res = es.bulk(index='product', body=bulk_data)

I've also tried to set _type to "", but that doesn't work either.

These are the error messages.

This is the error when I set _type to None:

elasticsearch.exceptions.RequestError: RequestError(400, 'action_request_validation_exception', 'Validation Failed: 1: type is missing;

and this is the error I get when I set _type to "":

java.lang.IllegalArgumentException: name cannot be empty string

Solution

  • Each index has one mapping type in Elasticsearch 6.x+. In Elasticsearch 7.x+ type is removed. In version 2.x - 5.6 you could have used more then one mapping. Assuming that you’re using version 6.x, you need to have type of documents in index.