Specify Mappings while creating index using python client

As far as I know, Elasticsearch by default takes in data and stores it as string (except for date). So, I have been using the body parameter in the create function of the Elasticsearch python client to specify the field mappings. But it results in a deprecated warning. I have been trying to find an alternative to the body parameter but couldn't find anything. Is there any other way of passing the mappings to the create function?

"Create" with body worked fine for me. Sharing problematic code may be recommended for future question :slight_smile:

https://elasticsearch-py.readthedocs.io/en/v7.16.2/api.html#indices

index='new_index'
body = {
            "settings": {...},
            "mappings": {...}
        }
es.indices.create(index, body)

Thank you! Just so you know the body parameter will be removed in future versions. I found the solution to this. You can pass the settings and mappings as separate arguments in the create function as follow:

index = 'new_index'
settings = {}
mappings = {}
es.indices.create(index=index, settings=settings, mappings=mappings)

1 Like

Thank you for sharing the solution!

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