ES Scripting - How to access a multi field value


(Britto) #1

I have a sub field named "util" defined in the ES mappings as shown below:

      "metric_value_number": {
        "type": "long",
        "fields": {
          "util": {
            "type": "double"
          }
        }
      }

In the Kibana UI, I have created a new scriping field named "CPU_UTL_PERCNT" and also added the following script against the field for calculation:
doc['metric_value_number.util'].value

Then I selected the field to perform a search. I am getting the following error now:
Discover: Field [metric_value_number.util] used in expression does not exist in mappings

Could any one please check it up and advice me on how to access the util field based on the above mapping?


(Kaib) #2

shouldn't it be

metric_value_number.fields.util

??


(Britto) #3

Thanks for your reply. But, It did not work. Now, I am getting the following error now:
Discover: Field [metric_value_number.fields.util] used in expression does not exist in mappings

I have received the following in the error stack trace:
"Error during search with inline script [doc['metric_value_number.fields.util'].value] using lang [expression]","caused_by":{"type":"expression_script_compilation_exception","reason":"Field [metric_value_number.fields.util] used in expression does not exist in mappings"}}}]}}


(Britto) #4

Even I tried with the following syntax: metric_value_number.fields[0].util

But, I have received the same error as follows:
Discover: Field [metric_value_number.fields[0].util] used in expression does not exist in mappings


(Britto) #5

Any update on this, please?


(Shelby Sturgis) #6

britto1981,

It seems you are attempting to use a mult_field type but you are defining it as a long. Not sure why in this case you are using a multi_field. Why not simply use:

"metric_value_number": {  "type": "long"  }.

If you are using a multi-field type, it should look like the following:

"metric_value_number": {
    "type": "multi_field",
    "fields" : {
        "util" : {  "type" : "double"  }
    }
}

Try doing that and let me know if that works.


(Shelby Sturgis) #7

Please ignore the previous comment. Bad advice since multi_field is dead.

Did you try refreshing your Kibana index?


(system) #8