Reputation: 487
doc1 = {
"field1": 34,
"field2": 15
}
doc2 = {
"field1": 12,
"field2": 46
}
How to match all the documents where field 1 is greater that field 2. That is in the above case the search will result in the matching of doc1 only.
Upvotes: 0
Views: 175
Reputation: 217324
You can use a script
filter that can directly compare the fields.
{
"query": {
"filtered": {
"filter": {
"script": {
"script": "doc.field1.value > doc.field2.value"
}
}
}
}
}
Note that in order for this to work you need to enable dynamic scripting.
Upvotes: 1