Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

query for one field doesn't equal another field in elasticsearch

How can I query for, or filter for, one field doesn't equal another field? i.e. where document1.city1.name not equal document1.city2.name.

Some version of this? http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-script-fields.html

like image 298
Darby Avatar asked Mar 04 '15 01:03

Darby


People also ask

How do I use not equal in Elasticsearch?

Similarly, to find documents whose field value is NOT equal to a given query string, you can do so using the NOT operator. If you want to find documents whose field value does not match multiple values, you need to use a space separated list. NOTE: you can also get the same results using a must_not boolean query.

What is term query in Elasticsearch?

Term queryedit. Returns documents that contain an exact term in a provided field. You can use the term query to find documents based on a precise value such as a price, a product ID, or a username.

What is Kibana query language?

The Kibana Query Language (KQL) is a simple syntax for filtering Elasticsearch data using free text search or field-based search. KQL is only used for filtering data, and has no role in sorting or aggregating the data. KQL is able to suggest field names, values, and operators as you type.


1 Answers

Yes , you will need to use script filter to achieve this

{
  "bool": {
    "filter": {
      "script": {
        "script": "doc['field1'].value !=  doc['field2'].value"
      }
    }
  }
}

You can find more information here

like image 79
Vineeth Mohan Avatar answered Nov 08 '22 03:11

Vineeth Mohan