Comparing elasticsearch between fields

Say I have documents with the following fields: {field1, field2, ... fieldn}

I need to run some queries in which, for some conditions, a comparison between two or more fields is required. like fieldX = fieldY

In standard SQL, an example might be:

 SELECT * FROM Table1 WHERE farePrice>100 AND originRegion = destinationRegion 

I read some documentation and it seems like "scripting" might be the only way to achieve this? Or are there other options?

+8
elasticsearch
source share
1 answer

You can use a script filter -

 { "filtered": { "query": { "range": { "farePrice": { "gt": 100 } } }, "filter": { "script": { "script": "doc['originRegion'].value == doc['destinationRegion'].value" } } } } 

You can find more information on here and here ,

+17
source share

All Articles