Facing error in query

(Shrikant) #1

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)

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

(Shrikant) #2

@elastic
Can someone Please help me out with this

(Shrikant) #3

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

(Henning Andersen) #4

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

The behaviour in 6.5 is explained here:

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.

1 Like
(Shrikant) #5

@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}