Searching on Scripted field fails with shard errors

Trying to filter the following scripted field Status column to show me only GOOD

When I enter a filter for this field, I get shard failures

A sample error seems to indicates that my script does not return a value in some of the exit conditions

But when I examine my script, there is a return statement for all paths

def good = new ArrayList();
def common_error_warning = new ArrayList();
def out = new ArrayList();

if(params._source.vehicle.sensors != null && params._source.vehicle.sensors.size() > 0) {
    for(int i = 0; i<params._source.vehicle.sensors.size(); i++ )
    {
      def go = params._source.vehicle.sensors[i];
      if(go.status.summary == 'Good'){
         if(good.contains(go.status.short_desc)){
                good.set(0, go.status.short_desc);
          }else {
                good.add(go.status.short_desc);
          }
      }
      else if(go.status.summary == 'Error'){
          if(common_error_warning.contains(go.status.short_desc)){
                common_error_warning.set(0, go.status.short_desc);
          }else {
                common_error_warning.add(go.status.short_desc);
          }
      }
      else if(go.status.summary == 'Warning'){
          if(common_error_warning.contains(go.status.short_desc)){
                common_error_warning.set(0, go.status.short_desc);
          }else {
                common_error_warning.add(go.status.short_desc);
          }
      }else {
          out.add( go.status.short_desc );
      }
    }
    if( common_error_warning.size() > 0 ) {
        return common_error_warning.toArray();
    }
    else if(good.size() > 0 && common_error_warning.size() == 0)
    {
        return good.toArray();
    }else
    {
        return out.toArray();
    }
}
return out.toArray();

and the error point seems to be outside of my script

Can anyone illuminate?

Thank you

Are you checking for "exists" in the script as well? That's the most common issue that causes this error.

Thank you for responding Marius,

You are correct,
Apparently the failure was due to params._source being null
Which was resolved by checking the whole path

if(params._source != null && 
   params._source.vehicle != null && 
   params._source.vehicle.sensors != null && 
   params._source.vehicle.sensors.size() > 0) 
{
....
}

So no longer get "Shard Failures" when adding a GOOD filter on the "Status" field...
Hurrayyy!

BUT I do get an unexpected "No results match your search criteria", which makes me feel that i have a type mismatch occurring on the return data.
Any Suggestions on strategies for resolving / diagnosing output of scripted fields?

Hmm, can you try removing the space before "GOOD"?

No Change / Difference

But if I remove/disable the filter, here is what i get

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