Skip to content

Instantly share code, notes, and snippets.

@eemp
Created September 24, 2015 21:53
Show Gist options
  • Save eemp/0e3df8552501bc2a79a6 to your computer and use it in GitHub Desktop.
Save eemp/0e3df8552501bc2a79a6 to your computer and use it in GitHub Desktop.
Find Elasticsearch records where a field is an array instead of a simple String
curl -w "\n" -XDELETE localhost:9200/scrap
curl -w "\n" -XPUT localhost:9200/scrap/ -d '
index :
number_of_replicas : 0
'
curl -w "\n" -XPUT localhost:9200/scrap/script-demo/1?refresh=1 -d '{
"fieldA" : "test string 1"
}'
curl -w "\n" -XPUT localhost:9200/scrap/script-demo/2?refresh=1 -d '{
"fieldA" : [
"test string 1",
"test string 2"
]
}'
curl -w "\n" -XPUT localhost:9200/scrap/script-demo/3?refresh=1 -d '{
"fieldA" : [
"test string 1"
]
}'
curl -w "\n" -XPOST localhost:9200/scrap/script-demo/_search -d '{
"query" : {
"filtered" : {
"filter" :{
"script" : {
"script" : "_source.fieldA.getClass() != String"
}
}
}
}
}' | python -m json.tool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment