Painless query - Iterate over map fields

Data

"discovery_workflow": {
        "WORKFLOW": {
          "START": {
            "process_name": "WORKFLOW",
            "state": "START",
            "event": {
              "time": 1542060483545
            }
          },
          "END": {
            "process_name": "WORKFLOW",
            "state": "END",
            "event": {
              "time": 1542060492975
            }
          }
        }
      }

Script:

GET test-index/_search
{
  "query": {
    "script": {
      "script": {
        "source": """
            String[] workflow_states = new String[] {'WORKFLOW', 'determine_package_metadata_format', 'validate_adi'};
              for (entry in workflow_states){
                if (doc['discovery_workflow'][entry].END == null) {
                  return true;
                }
              }
            return false;
""",
        "lang": "painless"
      }
    }
  }
}

The above is a sample of the data I'm working with, and the script I've written so far. I'm trying to write a Painless script to iterate through the keys to check if they exist, and if so, what their values are. I'm just returning right away because I haven't gotten it to work. I keep running into weird errors like "No field found for [discovery_workflow] in mapping with types ".

Can anyone point me in the right direction please? Thanks!

That error means your query is running against an index that does not contain the field discovery_workflow. Are you sure the field exists?

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