Unable to filter with scripted field even through Add a filter

I have a scripted field setup with the following code:

List list = new ArrayList();
          Map m = new HashMap();
          m.put("usColpo", "colpo");
          m.put("vp", "visualPap");
          for (int i = 0; i <  doc['user.clinicalScenarios.keyword'].length; ++i) {
            def value = doc['user.clinicalScenarios.keyword'][i];
            } else {
          return list;

The original field clinicalScenario is a comma delimited string. It can have one or more values: usColpo, vp or usColpo, vp.
When I go to the discover tab I can see all the values populated correctly but when I add the filter examType:colpo no results are returned. Is it because I return a list to populate the field? I would ultimately like to add a filter control for this field so that I can filter on it in a dashboard.

Thanks You

Can you post an example of what your scripted field result looks like?

What does your mapping look like?

I tested using the below data with the mapping shown and it works.

Test Data

PUT test

POST test/_doc
  "examType": "colpo",
  "message": "1"

POST test/_doc
  "examType": "sane",
  "message": "2"

POST test/_doc
  "examType": "colpo, via",
  "message": "3"


        "examType" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256

I think I found the issue. It is because they are scripted array fields. This link seems to be my issue: https://github.com/elastic/kibana/issues/61597

1 Like

That could be it, yes.

My test as you see didn't reproduce the scripted field so that's why it worked for me. :slight_smile:

Have you tested this in a Control Visualization vs Filter Query? That could possibly work still.

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