Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

elasticsearch comparison between fields

Let's say I have documents with the following fields: {field1, field2, ... fieldn}

I need to run some queries where some of the conditions will require a comparison between two or more fields. like fieldX = fieldY

In standard SQL, an example could be:

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

I'be been reading some documentation, and it looks "scripting" could be the only way to achieve this? Or are there any other options?

like image 301
jdiaz4517 Avatar asked Dec 30 '14 16:12

jdiaz4517


1 Answers

You can use the script filter -

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

You can find more information at here and here .

like image 146
Vineeth Mohan Avatar answered Nov 20 '22 10:11

Vineeth Mohan