Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

range filter on date_range datatype should use the format defined in the mapping #29282

Closed
dadoonet opened this issue Mar 28, 2018 · 1 comment
Labels
>bug help wanted adoptme :Search/Search Search-related issues that do not fall into other categories

Comments

@dadoonet
Copy link
Member

Tested on 6.2.3:

This is a Range query on a date field:

DELETE test
PUT test
{
  "mappings": {
    "_doc": {
      "properties": {
        "mydate": {
          "type": "date", 
          "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
        }
      }
    }
  }
}
PUT test/_doc/1
{
  "mydate" : "2015-10-31 12:00:00"
}
GET test/_search
{
  "query": {
    "range": {
      "mydate": {
        "gte": "2015-10-31 12:00:00"
      }
    }
  }
}

This works well.

This is a Range query on a date_range field:

DELETE range_index
PUT range_index
{
  "mappings": {
    "_doc": {
      "properties": {
        "time_frame": {
          "type": "date_range", 
          "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
        }
      }
    }
  }
}
PUT range_index/_doc/1
{
  "time_frame" : { 
    "gte" : "2015-10-31 12:00:00", 
    "lte" : "2015-11-01"
  }
}
GET range_index/_search
{
  "query" : {
    "range" : {
      "time_frame" : {
        "gte" : "2015-10-31 12:00:00",
        "lte" : "2015-11-01",
        "relation" : "within" 
      }
    }
  }
}

This is failing with:

      {
        "type": "parse_exception",
        "reason": "failed to parse date field [2015-10-31 12:00:00] with format [strict_date_optional_time||epoch_millis]"
      }

We can see that the format defined in the mapping is not used here. It should use yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis but it uses strict_date_optional_time||epoch_millis.

If we manually force the format to be the same as the mapping, then it works:

GET range_index/_search
{
  "query" : {
    "range" : {
      "time_frame" : {
        "gte" : "2015-10-31 12:00:00",
        "lte" : "2015-11-01",
        "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||yyyy", 
        "relation" : "within" 
      }
    }
  }
}

I suggest that we try first to use the mapping defined for the field and fallback to the default one if needed.

cc @melvynator

@dadoonet dadoonet added >bug :Search/Search Search-related issues that do not fall into other categories labels Mar 28, 2018
@hub-cap hub-cap removed the :Search/Search Search-related issues that do not fall into other categories label Mar 29, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

@hub-cap hub-cap added the :Search/Search Search-related issues that do not fall into other categories label Mar 29, 2018
@colings86 colings86 added the help wanted adoptme label Mar 29, 2018
liketic added a commit to liketic/elasticsearch that referenced this issue Mar 30, 2018
cbuescher pushed a commit that referenced this issue May 9, 2018
…29310)

If the date format is not forced in query, use the format in mapping before 
fallback to the default format.

Closes #29282
cbuescher pushed a commit that referenced this issue May 9, 2018
…29310)

If the date format is not forced in query, use the format in mapping before 
fallback to the default format.

Closes #29282
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug help wanted adoptme :Search/Search Search-related issues that do not fall into other categories
Projects
None yet
Development

No branches or pull requests

4 participants