I'm trying to use Elasticsearch to return docs that have different terms in two fields. Not knowing how to write this it would be something like this:
query:
field1: "term set #1"
field2: "very different term set #2"
Ideally the term sets would be arrays of strings. I'd like all terms and field hits to be ORed so the best docs would have all hits in each field but if any field had none, that would be ok.
You can use Terms Query
and bool should
for achieving this assuming that you want to match the exact values without analysis. The beauty of Terms Query
is that it implicitly works with an array of values and it implicitly is an OR
operation.
{
"query": {
"bool": {
"should": [
{
"terms": {
"field1": [
"field1 value1",
"field1 value2",
"field1 value3"
]
}
},
{
"terms": {
"field2": [
"field2 value1",
"field2 value2",
"field2 value3"
]
}
}
]
}
}
}