-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Description
Currently, we are specifying custom date formats for some date fields in index templates, like:
"format": "yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ||yyyy-MM-dd'T'HH:mm:ssZ||dateOptionalTime",
"type": "date"
The following is a simple script that tests if Elasticsearch can index values formatted using those patterns out of the box (script available also here).
#!/bin/bash
ES=http://localhost:9200
function delete_index() {
curl -X DELETE "${ES}/test"
}
function refresh() {
curl -X POST "${ES}/_refresh"
}
function index_document() {
echo "Testing $1"
curl -X POST "${ES}/test/1" -d "{
\"date\": \"$1\"
}"
}
function mapping() {
curl -X GET "${ES}/test/_mapping?pretty"
}
# test formats: "yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ||yyyy-MM-dd'T'HH:mm:ssZ"
for i in 2014-01-17T15:57:22.123456Z 2014-01-17T15:57:22Z
do
delete_index
index_document $i
mapping
refresh
doneWe can see below the values are correctly indexed. I think it makes sense to add only those custom formats that are not indexed by default (this means we are declaring we expect those format). When declaring formats that are indexed out of the box I wonder if this can contribute to later confusion ("Did we have issues indexing those values? What kind of issues?").
Results for Elasticsearch:
v1.7.2
# Testing 2014-01-17T15:57:22.123456Z
{"_index":"test","_type":"1","_id":"AVdRJMoWGkau0j2E_IYd","_version":1,"created":true}{
"test" : {
"mappings" : {
"1" : {
"properties" : {
"date" : {
"type" : "date",
"format" : "dateOptionalTime"
}}}}}}
# Testing 2014-01-17T15:57:22Z
{"_index":"test","_type":"1","_id":"AVdRJMtNGkau0j2E_IYe","_version":1,"created":true}{
"test" : {
"mappings" : {
"1" : {
"properties" : {
"date" : {
"type" : "date",
"format" : "dateOptionalTime"
}}}}}}v2.3.5
# Testing 2014-01-17T15:57:22.123456Z
{"_index":"test","_type":"1","_id":"AVdRJlQxVUFkKwD07My_","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}{
"test" : {
"mappings" : {
"1" : {
"properties" : {
"date" : {
"type" : "date",
"format" : "strict_date_optional_time||epoch_millis"
}}}}}}
# Testing 2014-01-17T15:57:22Z
{"_index":"test","_type":"1","_id":"AVdRJlVtVUFkKwD07MzA","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}{
"test" : {
"mappings" : {
"1" : {
"properties" : {
"date" : {
"type" : "date",
"format" : "strict_date_optional_time||epoch_millis"
}}}}}}v2.4.0
# Testing 2014-01-17T15:57:22.123456Z
{"_index":"test","_type":"1","_id":"AVdRJxF4bHsb53sfaNXO","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}{
"test" : {
"mappings" : {
"1" : {
"properties" : {
"date" : {
"type" : "date",
"format" : "strict_date_optional_time||epoch_millis"
}}}}}}
# Testing 2014-01-17T15:57:22Z
{"_index":"test","_type":"1","_id":"AVdRJxLKbHsb53sfaNXP","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}{
"test" : {
"mappings" : {
"1" : {
"properties" : {
"date" : {
"type" : "date",
"format" : "strict_date_optional_time||epoch_millis"
}}}}}}v5.0.0-alpha5
# Testing 2014-01-17T15:57:22.123456Z
{"_index":"test","_type":"1","_id":"AVdRKG2bWRbH4ugGaVvq","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"created":true}{
"test" : {
"mappings" : {
"1" : {
"properties" : {
"date" : {
"type" : "date"
}}}}}}
# Testing 2014-01-17T15:57:22Z
{"_index":"test","_type":"1","_id":"AVdRKG7tWRbH4ugGaVvr","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"created":true}{
"test" : {
"mappings" : {
"1" : {
"properties" : {
"date" : {
"type" : "date"
}}}}}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels