Skip to content

Instantly share code, notes, and snippets.

@nickhoffman
Created May 11, 2012 02:25
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 nickhoffman/a29700e7c13baaa96a05 to your computer and use it in GitHub Desktop.
Save nickhoffman/a29700e7c13baaa96a05 to your computer and use it in GitHub Desktop.
ElasticSearch date detection in a dynamic template
In the index below, the dynamic template is configured to set its properties' type to "string".
However, when indexing the document below, the "attribs.hasbro_product_number" property's type is "date" instead of "string". Why?
This can be seen on lines 42-45 of the last file in this gist.
---
Update: It works now!
curl -X DELETE 'localhost:9200/hasbro'
echo
curl -X PUT 'localhost:9200/hasbro'
echo
curl -X PUT 'localhost:9200/hasbro/product/_mapping' -d '{
"product": {
"date_detection": true,
"dynamic_templates": [
{
"date_property": {
"match_mapping_type": "date",
"path_match" : "*attribs.*",
"mapping" : {
"type" : "multi_field",
"fields": {
"{name}": {
"type" : "string",
"index" : "analyzed",
"include_in_all": true
},
"orig": {
"type" : "string",
"index" : "not_analyzed",
"include_in_all": false
}
}
}
}
},
{
"string_property": {
"match_mapping_type": "string",
"path_match" : "*attribs.*",
"mapping" : {
"type" : "multi_field",
"fields": {
"{name}": {
"type" : "string",
"index" : "analyzed",
"include_in_all": true
},
"orig": {
"type" : "string",
"index" : "not_analyzed",
"include_in_all": false
}
}
}
}
}
]
}
}'
echo
curl -X PUT 'localhost:9200/hasbro/product/4eb1dd4a349c306bd50000a2' -d '{
"_type" : "product",
"id" : "4eb1dd4a349c306bd50000a2",
"name" : "Iron Man",
"attribs": { "hasbro_product_number" : "2009-001" }
}'
echo
curl -X POST 'localhost:9200/hasbro/_refresh'
echo
curl -X GET 'localhost:9200/hasbro/product/_mapping?pretty=true'
echo
{"ok":true,"acknowledged":true}
{"ok":true,"acknowledged":true}
{"ok":true,"acknowledged":true}
{"ok":true,"_index":"hasbro","_type":"product","_id":"4eb1dd4a349c306bd50000a2","_version":1}
{"ok":true,"_shards":{"total":1,"successful":1,"failed":0}}
{
"product" : {
"dynamic_templates" : [ {
"date_property" : {
"mapping" : {
"type" : "multi_field",
"fields" : {
"orig" : {
"include_in_all" : false,
"index" : "not_analyzed",
"type" : "string"
},
"{name}" : {
"include_in_all" : true,
"index" : "analyzed",
"type" : "string"
}
}
},
"match_mapping_type" : "date",
"path_match" : "*attribs.*"
}
}, {
"string_property" : {
"mapping" : {
"type" : "multi_field",
"fields" : {
"orig" : {
"include_in_all" : false,
"index" : "not_analyzed",
"type" : "string"
},
"{name}" : {
"include_in_all" : true,
"index" : "analyzed",
"type" : "string"
}
}
},
"match_mapping_type" : "string",
"path_match" : "*attribs.*"
}
} ],
"properties" : {
"id" : {
"type" : "string"
},
"_type" : {
"type" : "string"
},
"name" : {
"type" : "string"
},
"attribs" : {
"dynamic" : "true",
"properties" : {
"hasbro_product_number" : {
"type" : "multi_field",
"fields" : {
"hasbro_product_number" : {
"include_in_all" : true,
"type" : "string"
},
"orig" : {
"include_in_all" : false,
"index" : "not_analyzed",
"type" : "string"
}
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment