Skip to content

Instantly share code, notes, and snippets.

@baloghz
Created November 6, 2014 11:18
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 baloghz/c27e39ad419a6f4684ab to your computer and use it in GitHub Desktop.
Save baloghz/c27e39ad419a6f4684ab to your computer and use it in GitHub Desktop.
Test script to demonstrate strange behavior of script_fields of array
# delete index if exists
curl -XDELETE localhost:9200/test/
# create index with default settings
curl -XPOST localhost:9200/test/
# create mapping
curl -XPUT localhost:9200/test/user/_mapping -d '
{
"user": {
"properties": {
"id": {
"type": "string",
"index": "not_analyzed"
},
"other_ids": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
'
# add some data
curl -XPUT localhost:9200/test/user/id1 -d '
{
"id": "id1",
"other_ids": [
"id2",
"id3"
]
}
'
curl -XPUT localhost:9200/test/user/id2 -d '
{
"id": "id2",
"other_ids": [
"id1"
]
}
'
curl -XPUT localhost:9200/test/user/id3 -d '
{
"id": "id3",
"other_ids": [
"id1",
"id2"
]
}
'
# Query: test array values from script_fields
curl -XGET 'localhost:9200/test/user/_search?pretty=1' -d '
{
"fields": [
"_source"
],
"query": {
"match_all": {}
},
"script_fields": {
"other_id_script": {
"lang": "groovy",
"script": "doc[\"other_ids\"].values"
}
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment