# Facing error in query

**URL:** <https://discuss.elastic.co/t/facing-error-in-query/181520>\
**Category:** Elasticsearch\
**Created:** [May 17, 2019, 6:46am UTC](https://discuss.elastic.co/t/facing-error-in-query/181520 "2019-05-17T06:46:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![shrikantgulia](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@shrikantgulia](https://discuss.elastic.co/u/shrikantgulia)\
**Post date:** [May 17, 2019, 6:46am UTC](https://discuss.elastic.co/t/facing-error-in-query/181520/1 "2019-05-17T06:46:33Z")

</div>

Hello,

When I am running a query in elasticsearch I am facing a error

#! Deprecation: returning default values for missing document values is deprecated. Set system property '-Des.scripting.exception\_for\_missing\_value=true' to make behaviour compatible with future major versions!

when I am changing the value in the jvm.option(-Des.scripting.exception\_for\_missing\_value=true) than I am facing the error while running the query the error after changing the option is:

[_script\_exception_ ","reason":"runtime error"," _script stack_ ":["org.elasticsearch.index.fielddata.ScriptDocValues$Strings.getValue(ScriptDocValues.java:742)](https://www.google.com/search?q=script_exception%22,%22reason%22:%22runtime+error%22,%22script+stack%22:%5B%22org.elasticsearch.index.fielddata.ScriptDocValues%24Strings.getValue(ScriptDocValues.java:742)&spell=1&sa=X&ved=0ahUKEwjr-_rA-6HiAhVw7HMBHX6rD1AQBQgpKAA)

Before changing the value in jvm.option kibana is running perfectly but after changing the value it is throwing an error for the scripted field  
I am using 6.5 version of elastic

---

<div class="post-metadata">

**Author:** ![shrikantgulia](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@shrikantgulia](https://discuss.elastic.co/u/shrikantgulia)\
**Post date:** [May 20, 2019, 6:58am UTC](https://discuss.elastic.co/t/facing-error-in-query/181520/2 "2019-05-20T06:58:59Z")

</div>

@elastic  
Can someone Please help me out with this

---

<div class="post-metadata">

**Author:** ![shrikantgulia](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@shrikantgulia](https://discuss.elastic.co/u/shrikantgulia)\
**Post date:** [May 20, 2019, 7:02am UTC](https://discuss.elastic.co/t/facing-error-in-query/181520/3 "2019-05-20T07:02:45Z")

</div>

My query is

GET custom\_tpy\_cg112\_requests\_received/\_search  
{  
"aggs": {  
"2": {  
"terms": {  
"script": {  
"source": "def x = doc['mode'].value;\ndef y = "+513";\ndef t = "513";\nif (x == y){\nreturn t;\n}\nelse {\nreturn x;\n}",  
"lang": "painless"  
},  
"size": 5,  
"order": {  
"\_count": "desc"  
},  
"value\_type": "string"  
}  
}  
},  
"size": 0,  
"query": {  
"bool": {  
"must": [  
{  
"match\_all": {}  
},  
{  
"range": {  
"created": {  
"gte": 1526788838000,  
"lte": 1558116067002,  
"format": "epoch\_millis"  
}  
}  
}  
],  
"filter": ,  
"should": ,  
"must\_not":   
}  
}  
}

When I am querying data before 30 days than it is working but for query greater than 30 days it is throwing an error

---

<div class="post-metadata">

**Author:** ![HenningAndersen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/henningandersen/32/48188_2.png) [@HenningAndersen](https://discuss.elastic.co/u/HenningAndersen)\
**Post date:** [May 20, 2019, 8:58am UTC](https://discuss.elastic.co/t/facing-error-in-query/181520/4 "2019-05-20T08:58:35Z")

</div>

Hi @shrikantgulia,

the deprecation warning is about this breaking change in 7.0:

[https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.html#\_accessing\_missing\_document\_values\_will\_throw\_an\_error](https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.html#_accessing_missing_document_values_will_throw_an_error)

The behaviour in 6.5 is explained here:

[https://www.elastic.co/guide/en/elasticsearch/painless/6.5/painless-examples.html#\_missing\_values](https://www.elastic.co/guide/en/elasticsearch/painless/6.5/painless-examples.html#_missing_values)

I think the part of the script missing a check is: `doc['mode'].value`. Checking for `doc[mode].size() > 0` before accessing `.value` should fix it and thus make the script 7.0 compatible.

---

<div class="post-metadata">

**Author:** ![shrikantgulia](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@shrikantgulia](https://discuss.elastic.co/u/shrikantgulia)\
**Post date:** [May 21, 2019, 7:30am UTC](https://discuss.elastic.co/t/facing-error-in-query/181520/5 "2019-05-21T07:30:27Z")

</div>

@HenningAndersen,  
Still facing the error  
Can you please help me

error

Request to Elasticsearch failed: {"error":{"root\_cause":[{"type":"script\_exception","reason":"runtime error","script\_stack":["org.elasticsearch.index.fielddata.ScriptDocValues$Strings.getValue(ScriptDocValues.java:742)","x = doc['mode'].value;\ndef "," ^---- HERE"],"script":"def x = doc['mode'].value;\ndef y = "+515";\ndef z = "515";\nif (x==y){\nreturn z;\n}\nelse {\nreturn x;\n}","lang":"painless"}],"type":"search\_phase\_execution\_exception","reason":"all shards failed","phase":"query","grouped":true,"failed\_shards":[{"shard":0,"index":"custom\_received","node":"\_wG9HMKKTQiDVyPaDhZ6aQ","reason":{"type":"script\_exception","reason":"runtime error","script\_stack":["org.elasticsearch.index.fielddata.ScriptDocValues$Strings.getValue(ScriptDocValues.java:742)","x = doc['mode'].value;\ndef "," ^---- HERE"],"script":"def x = doc['mode'].value;\ndef y = "+515";\ndef z = "515";\nif (x==y){\nreturn z;\n}\nelse {\nreturn x;\n}","lang":"painless","caused\_by":{"type":"illegal\_state\_exception","reason":"A document doesn't have a value for a field! Use doc[].size()==0 to check if a document is missing a field!"}}}]},"status":500}

---

<div class="post-metadata">

**Author:** ![shrikantgulia](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@shrikantgulia](https://discuss.elastic.co/u/shrikantgulia)\
**Post date:** [May 27, 2019, 5:27am UTC](https://discuss.elastic.co/t/facing-error-in-query/181520/6 "2019-05-27T05:27:02Z")

</div>

@HenningAndersen,

A humble request  
Please can you look into this

Regards

---

<div class="post-metadata">

**Author:** ![HenningAndersen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/henningandersen/32/48188_2.png) [@HenningAndersen](https://discuss.elastic.co/u/HenningAndersen)\
**Post date:** [May 27, 2019, 10:25am UTC](https://discuss.elastic.co/t/facing-error-in-query/181520/7 "2019-05-27T10:25:06Z")

</div>

Hi @shrikantgulia,

Following is an example of a scripted terms aggregation using ternary ? operator to extract the value safely:

```auto
GET test/_search?pretty
{
  "aggs": {
    "2" : {
      "terms": {
	"script": {
	  "source": "def x = doc['mode'].size() == 0 ? \"empty\" : doc['mode'].value; return x;",
	  "lang": "painless"
	}
      }
    }
  }
}

```

---

<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:** [June 24, 2019, 10:25am UTC](https://discuss.elastic.co/t/facing-error-in-query/181520/8 "2019-06-24T10:25:07Z")

</div>

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