Skip to content

Order not working inside a date_histogram aggs ES 2.0 #14771

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

Closed
damienbod opened this issue Nov 15, 2015 · 5 comments
Closed

Order not working inside a date_histogram aggs ES 2.0 #14771

damienbod opened this issue Nov 15, 2015 · 5 comments
Labels

Comments

@damienbod
Copy link

POST http://localhost:9200/searchaggtests/searchaggtest/_search?&search_type=count HTTP/1.1
Content-Type: application/json
Host: localhost:9200
Content-Length: 289
Expect: 100-continue

{"aggs":{"testHistogramBucketAggregation":{"date_histogram":{"field":"dateofdetails","interval":"1M","format":"yyyy-MM-dd","offset":"1d","time_zone":"+02:00","order":{"dateofdetails":"desc"},"min_doc_count":2,"extended_bounds":{"min":0,"max":1000000}},"aggs":{"tophits":{"top_hits":{}}}}}}

Result:

HTTP/1.1 503 Service Unavailable
Content-Type: application/json; charset=UTF-8
Content-Length: 293

{"error":{"root_cause":[],"type":"reduce_search_phase_exception","reason":"[reduce] ","phase":"query","grouped":true,"failed_shards":[],"caused_by":{"type":"illegal_argument_exception","reason":"Invalid order path [dateofdetails]. Cannot find aggregation named [dateofdetails]"}},"status":503}

Greetings Damien

@clintongormley
Copy link
Contributor

This is weird for a few reasons...

  • you can't sort on fields, only on the result of aggregations so the exception is correct

  • it shouldn't be returning a 503 response though

  • when I try it (full example below) on 2.0, I don't get this exception, which i should

    POST _bulk
    {"index":{"_index":"searchtests","_type":"searchtest","_id":1}}
    {"id":1,"name":"one","details":"This is the details of the document, very interesting","circletest":{"type":"circle","coordinates":[45,45],"radius":"100m"},"location":[45,45],"lift":2.9,"dateofdetails":"2015-10-26T19:19:38.5961045Z"}
    {"index":{"_index":"searchtests","_type":"searchtest","_id":2}}
    {"id":2,"name":"two","details":"Details of the document two, leave it alone","circletest":{"type":"circle","coordinates":[46,45],"radius":"50m"},"location":[46,45],"lift":2.5,"dateofdetails":"2015-04-20T19:19:38.5961045Z"}
    {"index":{"_index":"searchtests","_type":"searchtest","_id":3}}
    {"id":3,"name":"three","details":"This data is different","circletest":{"type":"circle","coordinates":[37,42],"radius":"80m"},"location":[37,42],"lift":2.1,"dateofdetails":"2015-10-12T19:19:38.5961045Z"}

Full example:

POST searchtests/_search?search_type=count
{
  "aggs": {
    "testHistogramBucketAggregation": {
      "date_histogram": {
        "field": "dateofdetails",
        "interval": "1M",
        "format": "yyyy-MM-dd",
        "offset": "1d",
        "time_zone": "+02:00",
        "order": {
          "dateofdetails": "desc"
        },
        "min_doc_count": 2,
        "extended_bounds": {
          "min": 0,
          "max": 1000000
        }
      },
      "aggs": {
        "tophits": {
          "top_hits": {}
        }
      }
    }
  }
}

@colings86 any ideas?

@colings86
Copy link
Contributor

I get the same as @clintongormley.

This is a bug because an exception should be thrown and the status code returned should be 400 (bad request).

@colings86 colings86 added good first issue low hanging fruit help wanted adoptme >bug and removed discuss labels Nov 18, 2015
@colings86 colings86 removed their assignment Nov 20, 2015
qwerty4030 added a commit to qwerty4030/elasticsearch that referenced this issue Aug 7, 2016
Updated SearchPhaseExecutionException to determine the status from the cause if one exists and there were no shard failures.

Throw exception if (date) histogram order path is invalid and there is only one bucket.
Forced check of sub-aggregation names and fields used in (date) histogram order path if there is only one bucket. The previous code relied on the sorting code (bypassed if less than 2 buckets) to do this check. Ideally these checks should be performed during parsing instead of the reduce phase.

Closes elastic#14771
qwerty4030 added a commit to qwerty4030/elasticsearch that referenced this issue May 11, 2017
This commit adds support for histogram and date_histogram agg compound order by refactoring and reusing terms agg order code. The major change is that the Terms.Order and Histogram.Order classes have been replaced/refactored into a new class BucketOrder. This is a breaking change for the Java Transport API. For backward compatibility with previous ES versions the (date)histogram compound order will use the first order. Also the _term and _time aggregation order keys have been deprecated; replaced by _key.

Relates to elastic#20003: now that all these aggregations use the same order code, it should be easier to move validation to parse time (as a follow up PR).

Relates to elastic#14771: histogram and date_histogram aggregation order will now be validated at reduce time.

Closes elastic#23613: if a single BucketOrder that is not a tie-breaker is added with the Java Transport API, it will be converted into a CompoundOrder with a tie-breaker.
colings86 pushed a commit that referenced this issue May 11, 2017
This commit adds support for histogram and date_histogram agg compound order by refactoring and reusing terms agg order code. The major change is that the Terms.Order and Histogram.Order classes have been replaced/refactored into a new class BucketOrder. This is a breaking change for the Java Transport API. For backward compatibility with previous ES versions the (date)histogram compound order will use the first order. Also the _term and _time aggregation order keys have been deprecated; replaced by _key.

Relates to #20003: now that all these aggregations use the same order code, it should be easier to move validation to parse time (as a follow up PR).

Relates to #14771: histogram and date_histogram aggregation order will now be validated at reduce time.

Closes #23613: if a single BucketOrder that is not a tie-breaker is added with the Java Transport API, it will be converted into a CompoundOrder with a tie-breaker.
@qwerty4030
Copy link
Contributor

qwerty4030 commented May 14, 2017

As of #22343 histogram and date_histogram aggregation order will now be validated during the shard search phase. We now get the same validation errors as the terms agg when an invalid sub-aggregation is given in the order.

PUT i

POST i/_search
{
  "aggs": {
    "a": {
      "date_histogram": {
        "field": "f", 
        "interval": "day", 
        "order": {
          "wrong": "asc"
        }
      }
    }
  }
}

response:
{
  "error": {
    "root_cause": [
      {
        "type": "aggregation_execution_exception",
        "reason": "Invalid aggregator order path [wrong]. Unknown aggregation [wrong]"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "i",
        "node": "jUa3xSiEQTayFeYCYHt2jg",
        "reason": {
          "type": "aggregation_execution_exception",
          "reason": "Invalid aggregator order path [wrong]. Unknown aggregation [wrong]"
        }
      }
    ]
  },
  "status": 500
}

The order code was refactored in #22343 so it will now be easier to move order validation for all aggregations to the query parsing phase as a follow up PR.

@polyfractal
Copy link
Contributor

@elastic/es-search-aggs

@polyfractal
Copy link
Contributor

Actually, closing in favor of #20003

Sorry for the noise :)

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

No branches or pull requests

5 participants