Skip to content

Instantly share code, notes, and snippets.

@Avatah
Created February 10, 2012 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Avatah/1788431 to your computer and use it in GitHub Desktop.
Save Avatah/1788431 to your computer and use it in GitHub Desktop.
Elastic Search date_format problem
ES 0.18.6 & ES 0.19.0.RC2
curl -XPUT http://localhost:9200/i
curl -XPUT http://localhost:9200/i/t1/_mapping -d '
{ "t1" : {
"dynamic_templates" : [
{
"no_analyze_strings" : {
"match_mapping_type" : "string",
"match" : "*",
"mapping" : {
"type" : "string",
"index" : "not_analyzed"
}
}
}]
}}'
curl -XPUT http://localhost:9200/i/t1/1 -d '
{ "basic_date" : "20120209T180027.513+0100", "date_opt_time" : "2012-02-09T18:00:27.513+0100"} '
curl -XGET http://localhost:9200/i/t1/_mapping
{"t1":{"dynamic_templates":[{"no_analyze_strings":{"mapping":{"index":"not_analyzed","type":"string"},"match_mapping_type":"string","match":"*"}}],"properties":{"date_opt_time":{"format":"dateOptionalTime","type":"date"},"basic_date":{"index":"not_analyzed","type":"string"}}}}
^^^ Date optional time format was correctly parsed as a date, and basic_date_time format was not, so because no_analyze_strings is defined it's not analyzed. That's correct.
But in our app we use basic_date_time format so we defined it as default format:
curl -XPUT http://localhost:9200/i/t2/_mapping -d '
{ "t2" : {
"date_formats" : [ "basic_date_time" ],
"dynamic_templates" : [
{
"no_analyze_strings" : {
"match_mapping_type" : "string",
"match" : "*",
"mapping" : {
"type" : "string",
"index" : "not_analyzed"
}
}
}]
}}'
curl -XPUT http://localhost:9200/i/t2/1 -d '
{ "basic_date" : "20120209T180027.513+0100", "date_opt_time" : "2012-02-09T18:00:27.513+0100"} '
curl -XGET http://localhost:9200/i/t2/_mapping
{"t2":{"dynamic_templates":[{"no_analyze_strings":{"mapping":{"index":"not_analyzed","type":"string"},"match_mapping_type":"string","match":"*"}}],"properties":{"date_opt_time":{"index":"not_analyzed","type":"string"},"basic_date":{"index":"not_analyzed","type":"string"}},"dynamic_date_formats":["basic_date_time"]}}
^^^ And here is the problem. "date_opt_time" was not recognized as a date which is correct, but why "basic_date" wasn't?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment