Skip to content

Instantly share code, notes, and snippets.

@imotov
Created July 3, 2012 15:42
Show Gist options
  • Select an option

  • Save imotov/3040566 to your computer and use it in GitHub Desktop.

Select an option

Save imotov/3040566 to your computer and use it in GitHub Desktop.
Script source demo
curl -XDELETE http://localhost:9200/test-index
echo
curl -XPUT http://localhost:9200/test-index -d '{
"settings" : {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 0
}
},
"mappings" : {
"rec" : {
"_source" : { "enabled" : false },
"_id" : {"store" : "yes"},
"properties": {
"text": {"type": "string"},
"test_field": {"type": "string"}
}
}
}
}'
echo
curl -XPUT http://localhost:9200/test-index/rec/1 -d '{"text": "This is a record", "num" : 10}'
echo
curl -XPUT http://localhost:9200/test-index/rec/2 -d '{"text": "This is another record", "num" : 20}'
echo
curl -XPOST http://localhost:9200/test-index/_refresh
echo
curl "http://localhost:9200/test-index/_search?pretty=true" -d '{
"query": {
"query_string": {
"query": "record OR script"
}
},
"highlight": {
"fields": {
"text": {"fragment_size": 100, "number_of_fragments": 1}
}
},
"fields": ["_source", "num"],
"script_fields" : {
"num_plus_five" : {
"script" : "_source.num + 5"
}
},
"script_source" : {
"script" : "repl_source[_fields._id.value]",
"params" : {
"repl_source" : {
"1" : {
"text" : "This is a record (from script)",
"num" : 11
},
"2" : {
"text" : "This is another record (from script)",
"num" : 21
}
}
}
},
"sort": ["_score"]
}'
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment