I can set mappings of index being created in curl command like this:
{
"mappings":{
"logs_june":{
"_timestamp":{
"enabled":"true"
},
"properties":{
"logdate":{
"type":"date",
"format":"dd/MM/yyy HH:mm:ss"
}
}
}
}
}
But I need to create that index with elasticsearch client in python and set mappings.. what is the way ? I tried somethings below but not work:
self.elastic_con = Elasticsearch([host], verify_certs=True)
self.elastic_con.indices.create(index="accesslog", ignore=400)
params = "{\"mappings\":{\"logs_june\":{\"_timestamp\": {\"enabled\": \"true\"},\"properties\":{\"logdate\":{\"type\":\"date\",\"format\":\"dd/MM/yyy HH:mm:ss\"}}}}}"
self.elastic_con.indices.put_mapping(index="accesslog",body=params)
You can simply add the mapping in the
create
call like this:Well, there is easier way to do this with general python syntax:
Another python client sample of how to raise field limit through create index
The Python API client can be a tricky to work with and it often requires you to provide the inner portions of JSON spec documentations to keyword arguments.
For the
put_mapping
method, instead of providing it the full "mappings" JSON document you must give it thedocument_type
parameter and only the inner portion of the "mappings" document like so: