Skip to content

Instantly share code, notes, and snippets.

@amrelhagary
Last active August 29, 2015 14:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amrelhagary/f664c4bc239698a9b293 to your computer and use it in GitHub Desktop.
Save amrelhagary/f664c4bc239698a9b293 to your computer and use it in GitHub Desktop.
use external groovy script for elasticsearch1.3.x transform
curl -XDELETE 'localhost:9200/test'
curl -XPOST 'localhost:9200/test' -d '
{
"mappings": {
"test_type": {
"transform": {
"lang": "groovy",
"script": "dynamicTransformScript"
},
"dynamic_templates": [
{
"dynamic_field": {
"match": "dynamic_[1-9]",
"match_mapping_type": "string",
"mapping": {
"type": "string"
}
}
}
]
}
}
}
'
curl -XPUT 'localhost:9200/test/test_type/1' -d'
{
"field_values": "dynamic_1,dynamic_2,dynamic_3"
}
'
curl -XGET 'localhost:9200/test/test_type/1?_source_transform&pretty'
/**
* adding dynamic fields according to field values
*/
if(ctx._source.field_values != ''){
def dynamicFields = ctx._source.field_values.split(',');
for(x in dynamicFields){
ctx._source[x] = x;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment