Created
November 6, 2014 11:18
-
-
Save baloghz/c27e39ad419a6f4684ab to your computer and use it in GitHub Desktop.
Test script to demonstrate strange behavior of script_fields of array
This file contains 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
# 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