# Elasticsearch script breaking change query Accessing missing document value

**URL:** <https://discuss.elastic.co/t/elasticsearch-script-breaking-change-query-accessing-missing-document-value/264096>\
**Category:** Elasticsearch\
**Created:** [February 12, 2021, 8:46am UTC](https://discuss.elastic.co/t/elasticsearch-script-breaking-change-query-accessing-missing-document-value/264096 "2021-02-12T08:46:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sardar\_nale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sardar_nale/32/83759_2.png) [@sardar\_nale](https://discuss.elastic.co/u/sardar_nale)\
**Post date:** [February 12, 2021, 8:46am UTC](https://discuss.elastic.co/t/elasticsearch-script-breaking-change-query-accessing-missing-document-value/264096/1 "2021-02-12T08:46:21Z")

</div>

Hi all,

We are using elastic version 7.10.2 and it is migrated from 6.8.6.  
I want to compare two fields from a same document using Scripting .Below query was working in elastic version 6.8.6 now after upgrade to 7.10 its not working

Here is my query : find records where nickname is equal to firstname.

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

```

It gives error like script\_exception  
Reason: all shards failed and  
"caused by":{  
"type":"illegal\_state\_exception",  
"reason":"A document doesnt have value for field! Use doc[].size()==0 to check if document is missing field"  
}

This issue specified in breaking changes in 7.0 here. It is because the field we have used in query is may be null for some records/document.

[Breaking changes in 7.0 | Elasticsearch Reference [7.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.html#breaking_70_scripting_changes)

To resolve this issue I have added condition like doc[].size!=0 now error is gone but it did not give any records in response (empty response in hits:) but in elastic I have records where nickname == firstname. Kindly help

**New Query**

```auto
{
  "query": {
    "bool": {
      "must": [{
        "script": {
          "script": {
            "inline": "doc['nickname.keyword'].size()!=0 && doc['firstname.keyword'].size()!=0 &&doc['nickname.keyword'].value == doc['firstname.keyword'].value",
            "lang": "painless",
            
          }
        } 
      }]
    }
  }
}

```

I also tried put same script in filter instead of must but that also not worked.  
and using doc['nickname.keyword'].size()\>0 instead ofdoc['nickname.keyword'].size()!=0 also not worked. Kindly help

---

<div class="post-metadata">

**Author:** ![Chandan\_Kushwaha](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chandan_kushwaha/32/83833_2.png) [@Chandan\_Kushwaha](https://discuss.elastic.co/u/Chandan_Kushwaha)\
**Post date:** [February 12, 2021, 11:43am UTC](https://discuss.elastic.co/t/elasticsearch-script-breaking-change-query-accessing-missing-document-value/264096/2 "2021-02-12T11:43:34Z")

</div>

Hi,  
Kindly use this query

```
{
  "query": {
    "bool": {
      "must": [{
        "script": {
          "script": {
            "inline": "doc['nickname.keyword'].size()!=0 && doc['firstname.keyword'].size()!=0 &&doc['nickname.keyword'].value.equalsIgnoreCase(doc['firstname.keyword'].value)",
            "lang": "painless",
            
          }
        } 
      }]
    }
  }
}

```

"==" operator compares object references while equalsIgnoreCase() compares both strings ignoring case.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 12, 2021, 11:43am UTC](https://discuss.elastic.co/t/elasticsearch-script-breaking-change-query-accessing-missing-document-value/264096/3 "2021-03-12T11:43:39Z")

</div>

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