# Ingest Node - Script Processor not recognizing field as number

**URL:** <https://discuss.elastic.co/t/ingest-node-script-processor-not-recognizing-field-as-number/214053>\
**Category:** Elasticsearch\
**Created:** [January 7, 2020, 12:46pm UTC](https://discuss.elastic.co/t/ingest-node-script-processor-not-recognizing-field-as-number/214053 "2020-01-07T12:46:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gferrette](https://avatars.discourse-cdn.com/v4/letter/g/bbce88/32.png) [@gferrette](https://discuss.elastic.co/u/gferrette)\
**Post date:** [January 7, 2020, 12:46pm UTC](https://discuss.elastic.co/t/ingest-node-script-processor-not-recognizing-field-as-number/214053/1 "2020-01-07T12:46:33Z")

</div>

Hello!

I'm trying to create a new field (of type double) that is the result of a calculation of another field, that is of type double too.  
I'm using filebeat to send the data to an ingest pipeline, and the ingest pipeline has a script processor to do this calculation, as below:

{  
"script": {  
"lang": "painless",  
"source": "ctx.radius.log.Tempo\_Conexao = ctx.radius.log.OrigSessionTime / params.param\_c",  
"params": {  
"param\_c": 60.0  
}  
}  
}

The field ctx.radius.log.Tempo\_Conexao and ctx.radius.log.OrigSessionTime are both of type double, but the script processor is recognizing the field ctx.radius.log.OrigSessionTime as string, so i'm getting the error below:

Cannot apply [/] operation to types [java.lang.String] and [java.lang.Double].

Is there any way to cast the field ctx.radius.log.OrigSessionTime to double?

Thanks in advance!

ES version: 7.0.1

Att,

Gabriel.

---

<div class="post-metadata">

**Author:** ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)\
**Post date:** [January 7, 2020, 3:36pm UTC](https://discuss.elastic.co/t/ingest-node-script-processor-not-recognizing-field-as-number/214053/2 "2020-01-07T15:36:33Z")

</div>

> [@gferrette](#):
>
> "script": {  
> "lang": "painless",  
> "source": "ctx.radius.log.Tempo\_Conexao = ctx.radius.log.OrigSessionTime / params.param\_c",  
> "params": {  
> "param\_c": 60.0  
> }

Hi there!

Try something like

```
"script": {
  "lang": "painless",
  "source": """
    def OrigSessionTime = Double.parseDouble(ctx.radius.log.OrigSessionTime);
    ctx.radius.log.Tempo_Conexao = OrigSessionTime / params.param_c;
  """,
  "params": {
    "param_c": 60.0
  }
}

```

Simulating it in a pipeline it seems to work pretty well:

```
POST _ingest/pipeline/_simulate
{
  "docs": [
    {
      "_source": {
        "stringy_field": "600",
        "log": {}
      }
    }
  ]
  , "pipeline": {
    "processors": [
      {
        "script": {
          "source": """
            def doubly_field = Double.parseDouble(ctx.stringy_field);
            ctx.log.doubly_field = doubly_field / params.param_c; 
          """,
          "params": {
            "param_c": 60.0
          }
        }
      }
    ]
  }
}

```

returning:

```
{
  "docs" : [
    {
      "doc" : {
        "_index" : "_index",
        "_type" : "_doc",
        "_id" : "_id",
        "_source" : {
          "stringy_field" : "600",
          "log" : {
            "doubly_field" : 10.0
          }
        },
        "_ingest" : {
          "timestamp" : "2020-01-07T15:45:20.987Z"
        }
      }
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)\
**Post date:** [January 7, 2020, 3:49pm UTC](https://discuss.elastic.co/t/ingest-node-script-processor-not-recognizing-field-as-number/214053/3 "2020-01-07T15:49:38Z")

</div>

Also, if you have to use it in a ingest pipeline, I'd first look for the presence of all the needed fields before applying anything to them, in order to avoid breaking the script.

---

<div class="post-metadata">

**Author:** ![gferrette](https://avatars.discourse-cdn.com/v4/letter/g/bbce88/32.png) [@gferrette](https://discuss.elastic.co/u/gferrette)\
**Post date:** [January 9, 2020, 7:36pm UTC](https://discuss.elastic.co/t/ingest-node-script-processor-not-recognizing-field-as-number/214053/4 "2020-01-09T19:36:01Z")

</div>

Hello Fabio!

It worked like a charm!!

Thanks very much!!!!

Gabriel.

---

<div class="post-metadata">

**Author:** ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)\
**Post date:** [January 10, 2020, 6:49am UTC](https://discuss.elastic.co/t/ingest-node-script-processor-not-recognizing-field-as-number/214053/5 "2020-01-10T06:49:35Z")

</div>

No problem.

Glad I could be of help 😉

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 7, 2020, 6:49am UTC](https://discuss.elastic.co/t/ingest-node-script-processor-not-recognizing-field-as-number/214053/6 "2020-02-07T06:49:45Z")

</div>

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