Compare two fields in same document without using script

Hi all,

We are using elastic version 7.10.2. I want to compare two fields from a same document.Scripting is disabled in my organization.
Kindly help in building below query without using script.
Here my query is : nickname is null or nickname is empty or nickname is equal to firstname.

Hard part is how to build query to get the records which have nickname is equal to firstname

Relevant script query to be converted to normal query :

{
  "query": {
    "bool": {
      "must": [{
        "script": {
          "script": {
            "inline": "doc['nickname.keyword'].value==null || doc['nickname.keyword'].value =='' || doc['nickname.keyword'].value == doc['firstname.keyword'].value",
            "lang": "painless",
            
          }
        } 
      }]
    }
  }
}

Comparing fields within a document as far as I know requires scripting. The only way around this would be to add another field that indicates whether the two fields are equal or not, but while that may work for a specific case it is not a general solution.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.