elasticsearch - How to query for values associated with a key across all documents? -
let's there documents in index this:
{ "properties":[ { "name":"foo", "value":"2" }, { "name":"boo", "value":"sausage" } ] }, { "properties":[ { "name":"foo", "value":"8" }, { "name":"boo", "value":"chicken" } ] }
i'd query index in way return properties.name
associated properties.value
values. result should contain this:
{ "foo":["2","8"], "boo":["chicken","sausage"] }
how can such result?
update: can achieve single query?
you can use multi search api:
$ cat requests {"index" : "test"} {"fields" : ["value"], "query" : {"term": {"properties.name": "foo"}}, "from" : 0, "size" : 1000} {"index" : "test"} {"fields" : ["value"], "query" : {"term" : {"properties.name": "boo"}}, , "from" : 0, "size" : 1000} $ curl -xget localhost:9200/_msearch --data-binary @requests;
or can use bool
query:
$ curl -xget localhost:9200/test/type -d '{ "from": 0, "size": 1000, "query": { "bool": { "should": [ { "match": { "properties.name": "foo" }}, { "match": { "properties.name": "boo" }} ] } } }
but need filter value yourself.
Comments
Post a Comment