What I would like to do is to retrieve all documents where a field value matches any of the values in an array.
So from an array of ids: [id1, id2, id3, ..., idn]
, find all documents which has any of these ids.
I can currently achieve that by repeating a match
inside of a should
, but it does not seem like the right approach.
{
"query": {
"bool": {
"should": [
{
"match": {
"activityOwnerId": "id1"
}
},
{
"match": {
"activityOwnerId": "id2"
}
},
... and so on
]
}
}
}
How can I get all documents which matches one of the elements in an array?
EDIT
Using terms
query as suggested by @Val does not return any results in Kibana:
If you're looking at exact matches, you can leverage the terms
query instead, which takes an array as input:
{
"query": {
"terms": {
"activityOwnerId.keyword": [id1, id2, id3, ..., idn]
}
}
}
There are two types of queries in elasicsearch
If you want to go form term query, then Answer mentioned by @Val, is perfect,
if you want to write a full-text query, you can use this
GET /_search
{
"query": {
"query_string": {
"query": "activityOwnerId:(id1 OR id2 OR id3...)"
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.