-
-
Save nickhoffman/a29700e7c13baaa96a05 to your computer and use it in GitHub Desktop.
ElasticSearch date detection in a dynamic template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"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