I created a scripted field with the name ("indexing_latency") now i want to use this scripted field in another scripted field which is like
def x = doc['indexing_latency'].value;
if ( x > 0) {
def z = 1;
return z
}
else {
def a = 0;
return a
}
but it is showing an error
Error with Painless scripted field 'def x = doc['indexing_latency'].value; if ( x > 0) { def z = 1; return z } else { def a = 0; return a }'
You can address this error by editing the ‘def x = doc['indexing_latency'].value; if ( x > 0) { def z = 1; return z } else { def a = 0; return a }’ field in Management > Index Patterns, under the “Scripted fields” tab.
Request to Elasticsearch failed: {"error":{"root_cause":[{"type":"script_exception","reason":"runtime error","script_stack":["org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:81)","org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:39)","x = doc['indexing_latency'].value;\n"," ^---- HERE"],"script":"def x = doc['indexing_latency'].value;\nif ( x > 0) {\ndef z = 1;\nreturn z\n}\nelse {\ndef a = 0;\nreturn a\n}","lang":"painless"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"fetch","grouped":true,"failed_shards":[{"shard":0,"index":"tpy_elk_instances_indexing_metric","node":"OLpIShaoSbaeggOPGnBRxA","reason":{"type":"script_exception","reason":"runtime error","script_stack":["org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:81)","org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:39)","x = doc['indexing_latency'].value;\n"," ^---- HERE"],"script":"def x = doc['indexing_latency'].value;\nif ( x > 0) {\ndef z = 1;\nreturn z\n}\nelse {\ndef a = 0;\nreturn a\n}","lang":"painless","caused_by":{"type":"illegal_argument_exception","reason":"No field found for [indexing_latency] in mapping with types []"}}}]},"status":500}
after that i also tried this
def x = doc['index_total'].value;
def y = doc['index_time_in_millis'].value;
{
if ( x > 0) {
def z = y / x;
return z
}
else {
def z = 5 * 0;
return z
}
}
if ( z > 0) {
def l = 0;
return l
}
else {
def f = 1;
return f
}
by creating the "indexing_latency" field and using it in the in loop but this is also throwing an error.
A help would be really appreciated
Best Regards
Shrikant