Skip to content

Instantly share code, notes, and snippets.

@hariinfo
Last active August 29, 2015 13:57
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 hariinfo/9403577 to your computer and use it in GitHub Desktop.
Save hariinfo/9403577 to your computer and use it in GitHub Desktop.
ES Dynamic template sample for deep object
-- Delete Index
curl -XDELETE 'http://localhost:9200/test_deep_object' && echo
-- Create Index
curl -XPOST 'http://localhost:9200/test_deep_object' && echo
--Create template
curl -XPUT http://localhost:9200/_template/test_deep_object_template?pretty -d '
{
"template" : "test_deep_object",
"order" : 10,
"settings" : {
"number_of_shards" : 5,
"index.number_of_replicas" : 0
},
"mappings" : {
"order": {
"dynamic_templates":[
{
"template_1" : {
"path_match" : "DataArea.Order.OrderAmount.*.#text",
"mapping" : {"type":"float","store":"yes","index":"analyzed"}
}
} ,
{
"zero_default" : {
"type" : "{dynamic_type}",
"match" :"*",
"mapping" : {"type":"{dynamic_type}","store":"yes","index":"analyzed"}
}
}
]
}
}
}'
-- Load a deep object
curl -XPUT 'http://localhost:9200/test_deep_object/order/0011' -d '{
"@releaseID": "1.0",
"@versionID": "1.0.1.1",
"ApplicationArea": {
"CreationDateTime": "2014-03-03T07:53:04.463Z"
},
"DataArea": {
"Order": {
"Channel": {
"ChannelIdentifer": {
"UniqueID": "10"
}
},
"OrderAmount": {
"GrandTotal": {
"@currency": "USD",
"#text": "1046.30"
},
"TotalProductPrice": {
"@currency": "USD",
"#text": "934.11"
},
"TotalAdjustment": {
"@currency": "USD",
"#text": "-10.29"
}
}
},
"Order_previous": {
"Channel":"MOBILE",
"OrderAmount": {
"GrandTotal": {
"@currency": "USD",
"#text": "1046.30"
},
"TotalProductPrice": {
"@currency": "USD",
"#text": "934.11"
},
"TotalAdjustment": {
"@currency": "USD",
"#text": "-10.29"
}
}
}
}
}'
-- Validate if the dynamic template was properly applied to the field
curl -XGET localhost:9200/test_deep_object/_mapping?pretty=true
-- Run an aggregation query on order total
curl -XGET 'http://localhost:9200/test_deep_object/_search?pretty=true' -d '{
"from" : 0, "size" : 5,
"query": {
"filtered": {
"filter": {
"range": { "CreationDateTime" : { "from" : "2014-03-01T00:00:00", "to" : "2014-03-06T00:00:00","include_lower" : true,"include_upper" : true}}
},
"query": { "match_all":{}} }},
"aggs" : {
"ordertotal" : {
"range" : {
"field" : "DataArea.Order.OrderAmount.GrandTotal.#text",
"keyed" : true,
"ranges" : [
{ "to" : 100 },
{ "from" : 100, "to" : 500},
{ "from" : 500, "to" : 1000},
{ "from" : 1000, "to" : 2000}
]
}
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment