Created
July 3, 2012 15:42
-
-
Save imotov/3040566 to your computer and use it in GitHub Desktop.
Script source demo
This file contains hidden or 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 -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