Skip to content

Conversation

@dadoonet
Copy link
Contributor

When the date format is defined in mapping, you can not use another format when querying using range date query or filter.

For example, this won't work:

DELETE /test

PUT /test/t/1
{
  "date": "2014-01-01"
}

GET /test/_search
{
  "query": {
    "filtered": {
      "filter": {
        "range": {
          "date": {
            "from": "01/01/2014"
          }
        }
      }
    }
  }
}

It causes:

Caused by: org.elasticsearch.ElasticsearchParseException: failed to parse date field [01/01/2014], tried both date format [dateOptionalTime], and timestamp number

It could be nice if we can support at query time another date format just like we support analyzer at search time on String fields.

Something like:

GET /test/_search
{
  "query": {
    "filtered": {
      "filter": {
        "range": {
          "date": {
            "from": "01/01/2014",
            "format": "dd/MM/yyyy"
          }
        }
      }
    }
  }
}

Same for queries:

GET /test/_search
{
  "query": {
    "range": {
      "date": {
        "from": "01/01/2014",
        "format": "dd/MM/yyyy"
      }
    }
  }
}

Closes #7189.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/help to support/help support/ and s/define/defined/ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 also applying this to range-query.asciidoc

@jpountz
Copy link
Contributor

jpountz commented Oct 6, 2014

Left some minor comments but it looks good overall

@jpountz jpountz removed the review label Oct 6, 2014
@dadoonet dadoonet added the review label Oct 6, 2014
@jpountz
Copy link
Contributor

jpountz commented Oct 6, 2014

LGTM

@jpountz jpountz removed the review label Oct 6, 2014
When the date format is defined in mapping, you can not use another format when querying using range date query or filter.

For example, this won't work:

```
DELETE /test

PUT /test/t/1
{
  "date": "2014-01-01"
}

GET /test/_search
{
  "query": {
    "filtered": {
      "filter": {
        "range": {
          "date": {
            "from": "01/01/2014"
          }
        }
      }
    }
  }
}
```

It causes:

```
Caused by: org.elasticsearch.ElasticsearchParseException: failed to parse date field [01/01/2014], tried both date format [dateOptionalTime], and timestamp number
```

It could be nice if we can support at query time another date format just like we support `analyzer` at search time on String fields.

Something like:

```
GET /test/_search
{
  "query": {
    "filtered": {
      "filter": {
        "range": {
          "date": {
            "from": "01/01/2014",
            "format": "dd/MM/yyyy"
          }
        }
      }
    }
  }
}
```

Same for queries:

```
GET /test/_search
{
  "query": {
    "range": {
      "date": {
        "from": "01/01/2014",
        "format": "dd/MM/yyyy"
      }
    }
  }
}
```

Closes elastic#7189.
@dadoonet dadoonet force-pushed the pr/7189-range-format-date branch from 980a417 to 6ae6a07 Compare October 6, 2014 14:00
@dadoonet dadoonet merged commit 6ae6a07 into elastic:master Oct 6, 2014
@dadoonet dadoonet deleted the pr/7189-range-format-date branch October 6, 2014 14:31
@mattweber
Copy link
Contributor

Sweet! Thanks @dadoonet! I just needed this feature, glad to see it will be in 1.5! If you can sneak it into 1.4 that would be even better.

@clintongormley clintongormley changed the title Search: add format support for date range filter and queries Add format support for date range filter and queries Jun 6, 2015
@clintongormley clintongormley added :Search/Search Search-related issues that do not fall into other categories and removed :Query DSL labels Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>feature :Search/Search Search-related issues that do not fall into other categories v1.5.0 v2.0.0-beta1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search: add format support for date range filter and queries

4 participants