ElasticSearch version: 6.3
mapping definition:
ES_DOCTYPE = {
"properties": {
"UsageEndDate": {"type": "date", "format": "YYYY-MM-dd HH:mm:ss"},
"UsageStartDate": {"type": "date", "format": "YYYY-MM-dd HH:mm:ss"}
}
}
json data:
{
'UsageEndDate': '2018-08-01 02:00:00',
'UsageStartDate': '2018-08-01 01:00:00'
}
{
'UsageEndDate': '2018-08-02 02:00:00',
'UsageStartDate': '2018-08-02 01:00:00'
}
create index:
es.index(index="test", doc_type='test', body=ES_DOCTYPE)
send data:
helpers.streaming_bulk(es, documents(), index="test", doc_type='test', chunk_size=1000)
hi I did my work google searching around, but maybe the keyword is too general so I didn't get much.
As I read documentation, ES should be able to find date format automatically, but even I add mapping definition, those UsageStartDate
or UsageEndDate
still shown as string
when I view them in Kibana.
Is there anything I'm missing?
thank you very much :)
I figured it out myself,
dynamicTemplate = {
"properties": {
"UsageEndDate": {"type": "date", "format": "YYYY-MM-dd HH:mm:ss"},
"UsageStartDate": {"type": "date", "format": "YYYY-MM-dd HH:mm:ss"}
}, "dynamic_templates": [
{
"notanalyzed": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
]
}
and put mapping definition first, then send data to ElasticSearch
es.indices.put_mapping(index="test", doc_type='test', body={'test': dynamicTemplate})
es.index(index='test-index', doc_type='tweet', body=ES_DOCTYPE)