Elasticsearch painless, how to determine the data type of a field
In es5.5, how to determine whether a field is numeric?
if (is_numeric(ctx._source.some)) {
    ctx._source.some = ctx._source.some + 2
}


Why don't you get the mapping and determine that? https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-field-mapping.html

i believe it can be done with painless. just don't get the way.

There is an instanceof that can be used to check against a reference type which you probably can use to define you own is_numeric function

"why don't you get the mapping" - maybe because the mapping varies across indices, and you want to find the type per document ... maybe to unearth some type conflicts? Well - that's what I'd like to do at the moment.

@sramalingam24 mapping is not necessary giving you the exact field type. By instance, a field can be an array or a concrete value, you cannot control that with mapping.

The instanceof operator might help here
if (ctx._source.some instanceof byte ||
    ctx._source.some instanceof short ||
    ctx._source.some instanceof int ||
    ctx._source.some instanceof long ||
    ctx._source.some instanceof float ||
    ctx._source.some instanceof double)
{
    ctx._source.some = ctx._source.some + 2
}


Another approach is to use Debug.explain, see https://www.elastic.co/guide/en/elasticsearch/painless/6.8/painless-debugging.html
This will abort with a painless_explain_error and the output will tell you what classes are involved. With that information (obtained manually from your various indices across your various ElasticSearch versions), you can then implement Painless with instanceof, as shown in @oleg-grishko 's answer.
POST /hockey/player/1/_explain
{
  "query": {
    "script": {
       "script": "Debug.explain(doc.goals)"
    }
  }
}

{
   "error": {
      "type": "script_exception",
      "painless_class": "org.elasticsearch.index.fielddata.ScriptDocValues.Longs",
       ...

