Elasticsearch: Date expressions are not fully working with decay functions

Created on 7 Nov 2017  路  2Comments  路  Source: elastic/elasticsearch

Elasticsearch version (bin/elasticsearch --version): 5.5.0 (same problem with 5.6.4)

Plugins installed: []

JVM version (java -version): 1.8.0_141

OS version (uname -a if on a Unix-like system): Darwin iMac 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64

Description of the problem including expected versus actual behavior:

Date expressions are not fully working with decay functions (exp, linear and gauss). Any valid values inside origin parameter seem to work fine but setting weeks, months and years (such as 3w, 3M or 3y) to offset and scale returns a parse exception:

failed to parse setting [DecayFunctionParser.offset] with value [3y] as a time value: unit is missing or unrecognized

Expected behavior is to make weeks, months and years values work with offset and scale parameters.

Steps to reproduce:

  1. Mappings:
curl -XPUT "http://localhost:9200/my_index" -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "my_type": {
      "properties": {
        "birthdate":  {
          "type": "date"
        } 
      }
    }
  }
}'
  1. Data:
curl -XPUT "http://localhost:9200/my_index/my_type/1" -H 'Content-Type: application/json' -d'
{
  "birthdate": "1990-01-20"
}'
curl -XPUT "http://localhost:9200/my_index/my_type/2" -H 'Content-Type: application/json' -d'
{
  "birthdate": "1996-02-18"
}'



md5-bb0e926a67d9abafbd9d5cc3a2bb3716



curl -XPUT "http://localhost:9200/my_index/my_type/3" -H 'Content-Type: application/json' -d'
{
  "birthdate": "1989-07-01"
}'



md5-d13ee176465e2ecb866a4f50e6732673



curl -XGET "http://localhost:9200/my_index/_search" -H 'Content-Type: application/json' -d'
{
  "query": {
    "function_score": {
      "query": {
        "match_all": {}
      },
      "functions": [
        {
          "gauss": {
            "birthdate": {
              "origin": "1996-01-01",
              "offset": "3y", 
              "scale": "3M"
            }
          }
        }
      ]
    }
  }
}'

Most helpful comment

Thanks for the reply @jimczi!

Is it possible to turn this into feature request, adding support for M, w and Y values?
It felt a bit inconsistent because those values are supported in date math, so I supposed they would also work elsewhere.

All 2 comments

Hi @callmekit,
The acceptable values for time units are defined here:
https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-units
M should work but in this context it means minutes and not month, y is not a valid unit.
I hope you don't mind if I close this issue since there is no bug or feature request in your issue.
If you have other questions like this please use the discuss forum:
https://discuss.elastic.co/c/elasticsearch
It is used by the community to ask and answers general questions about Elasticsearch.

Thanks for the reply @jimczi!

Is it possible to turn this into feature request, adding support for M, w and Y values?
It felt a bit inconsistent because those values are supported in date math, so I supposed they would also work elsewhere.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ttaranov picture ttaranov  路  3Comments

abtpst picture abtpst  路  3Comments

DhairyashilBhosale picture DhairyashilBhosale  路  3Comments

dadoonet picture dadoonet  路  3Comments

Praveen82 picture Praveen82  路  3Comments