'Calculate output in Elasticsearch Dev tools

Using Elasticsearch 7.*, we have a field 'ElapsedTime' under the mapping and I am trying to write a query to generate output of that field as 'ElapsedTime' / 1000. Tried below but no luck:

1)

GET /_search
{
  "script_fields": {
    "test1": {
      "script": {
        "lang": "painless",
        "source": "params._source.ElapsedTime / 1000"
      }
    }
  }
}
GET /_search
{
  "script_fields": {
    "test2": {
      "script": {
        "lang": "expression",
        "source": "doc['ElapsedTime'] / 1000"
      }
    }
  }
}

Errors:

  1. null pointer exception
  2. parse_exception: Field [ElapsedTime] does not exist in mappings


Solution 1:[1]

You need to run GET concrete-index/_search on a concrete-index and not on / which runs on all indexes of your cluster, where the chance of hitting an index which doesn't have ElapsedTime in its mapping is quite big.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Val