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

Elasticsearch 6.1.1 - Not possible to specify 'format' in Date Histogram aggregation when used in Composite Aggregation #27923

Closed
byronvoorbach opened this issue Dec 20, 2017 · 4 comments
Assignees

Comments

@byronvoorbach
Copy link
Contributor

byronvoorbach commented Dec 20, 2017

Hi all!

On Elasticsearch 6.1.1 I'm getting a:

{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "[composite] failed to parse field [sources]",
        "line": 26,
        "col": 17
      }
    ],
    "type": "parsing_exception",
    "reason": "[composite] failed to parse field [sources]",
    "line": 26,
    "col": 17,
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "[date_histogram] unknown field [format], parser not found"
    }
  },
  "status": 400
}

When trying to choose a format for my date_histogram aggregation, which is placed in a composite aggregation:

GET tickers/_search
{
  "size": 0,
  "aggs": {
    "compos": {
      "composite": {
        "size": 50,
        "sources": [
          {
            "currencyPair": {
              "terms": {
                "field": "currencyPair.raw"
              }
            }
          },
          {
            "exchanges": {
              "terms": {
                "field": "exchange.raw"
              }
            }
          },
          {
            "time" : {
              "date_histogram" : {
                "field": "date",
                "format" : "yyyy-MM-dd--HH:mm:ss.SSSZ",
                "interval": "5m"
              }
            }
          }
        ]
      }
    }
  }
}

Is this a possible bug? Or is it not possible to have a 'key_as_string' when using composite?
Here is the complete code to reproduce:

https://gist.github.com/byronvoorbach/434f84a8cf89f6aab9cb2d9e291a9047

@byronvoorbach byronvoorbach changed the title Elasticsearch 6.1.1 - Not possible to specify 'format' in Date Histogram aggregation when used in composite aggregation Elasticsearch 6.1.1 - Not possible to specify 'format' in Date Histogram aggregation when used in Composite Aggregation Dec 20, 2017
@jimczi
Copy link
Contributor

jimczi commented Dec 20, 2017

Is this a possible bug? Or is it not possible to have a 'key_as_string' when using composite?

This is not supported in 6.1, the composite agg returns the raw value but I agree that it should be possible to set a format for date fields in future versions. I marked this issue as a feature request and will update it when a pr is ready.

Thanks for testing the composite aggregation @byronvoorbach !

@jimczi jimczi added >feature and removed discuss labels Dec 20, 2017
@byronvoorbach
Copy link
Contributor Author

Hey @jimczi

Ahh okay! Thanks for your response! I'm enthusiastic about the composite aggregation :D Nice addition
I wouldn't mind working on a PR either if needed :)

@jimczi jimczi self-assigned this Dec 20, 2017
jimczi added a commit to jimczi/elasticsearch that referenced this issue Jan 19, 2018
This commit adds the ability to specify a date format on the `date_histogram` composite source.
If the format is defined, the key for the source is returned as a formatted date.

Closes elastic#27923
jimczi added a commit that referenced this issue Jan 23, 2018
…ce (#28310)

This commit adds the ability to specify a date format on the `date_histogram` composite source.
If the format is defined, the key for the source is returned as a formatted date.

Closes #27923
jimczi added a commit that referenced this issue Jan 24, 2018
…ce (#28310)

This commit adds the ability to specify a date format on the `date_histogram` composite source.
If the format is defined, the key for the source is returned as a formatted date.

Closes #27923
@DavidKHE
Copy link

Hi,

thank you for the resolution and the support for the format on composite date_histogram.

But, it seems to me that when using in AFTER_KEY. it is ignoring the date key when using formatted.

Is there any need to specify this differently?

Thanks,
David

@jimczi
Copy link
Contributor

jimczi commented Dec 26, 2018

@DavidKHE this issue is closed but you should be able to pass the after key with a formatted and a non-formatted date (a string or a long) when format is used. If you have a recreation that doesn't work please open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants