Skip to content

Instantly share code, notes, and snippets.

@thibault
Last active August 29, 2015 14:07
Show Gist options
  • Save thibault/f4462bf856d82174f94c to your computer and use it in GitHub Desktop.
Save thibault/f4462bf856d82174f94c to your computer and use it in GitHub Desktop.
Testing script_fields and _source
# (Re)create the index
curl -X DELETE 'http://localhost:9200/script-fields-test/'
curl -X PUT 'http://localhost:9200/script-fields-test/'
# Index documents
curl -X POST 'http://localhost:9200/script-fields-test/d/1' -d '{"title":"Title1", "count":1}'
curl -X POST 'http://localhost:9200/script-fields-test/d/2' -d '{"title":"Title1", "count":2}'
curl -X POST 'http://localhost:9200/script-fields-test/_refresh'
curl -X GET 'http://localhost:9200/script-fields-test/_search?pretty=true' -d '
{
"query" : { "match_all" : {} },
"script_fields" : {
"my_count" : {
"script" : "doc[\"count\"].value * factor",
"params" : {
"factor" : 2
}
}
}
}
'
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [ {
"_index" : "script-fields-test",
"_type" : "d",
"_id" : "1",
"_score" : 1.0,
"fields" : {
"my_count" : [ 2 ]
}
}, {
"_index" : "script-fields-test",
"_type" : "d",
"_id" : "2",
"_score" : 1.0,
"fields" : {
"my_count" : [ 4 ]
}
} ]
}
}
curl -X GET 'http://localhost:9200/script-fields-test/_search?pretty=true' -d '
{
"query" : { "match_all" : {} },
"fields" : ["_source"],
"script_fields" : {
"my_count" : {
"script" : "doc[\"count\"].value * factor",
"params" : {
"factor" : 2
}
}
}
}
'
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [ {
"_index" : "script-fields-test",
"_type" : "d",
"_id" : "1",
"_score" : 1.0,
"_source":{"title":"Title1", "count":1},
"fields" : {
"my_count" : [ 2 ]
}
}, {
"_index" : "script-fields-test",
"_type" : "d",
"_id" : "2",
"_score" : 1.0,
"_source":{"title":"Title1", "count":2},
"fields" : {
"my_count" : [ 4 ]
}
} ]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment