I wanted to query Elastic Search with the condition that the documents should contain the pair of values.
I have a pair of values, how can we query the elastic search with the pair.
Example: This is the indexed data
{
"messageId": "abc",
"Identifiers": {
"foo": "val1",
"bar": "val2"
},
"labels": {
"label1": "value1",
"label2": "value2"
}
}
I would like to retrieve the documents that matches the given pair of values.
For example if my pair is pair(val1, val2)
then, when we query the ES with the pair(val1, val2)
we should get the document with messageId
"abc"
CodePudding user response:
I believe that Bool Query with Must clausule would be an option.
{
"query": {
"bool": {
"must": [
{
"match": {
"Identifiers.foo": {
"query": "val1"
}
}
},
{
"match": {
"Identifiers.bar": {
"query": "val2"
}
}
}
]
}
}
}