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

stats aggregation returns 500 error when performed over an invalid field #12842

Closed
djschny opened this issue Aug 12, 2015 · 4 comments · Fixed by #12913
Closed

stats aggregation returns 500 error when performed over an invalid field #12842

djschny opened this issue Aug 12, 2015 · 4 comments · Fixed by #12913
Labels
:Analytics/Aggregations Aggregations >bug :Core/Infra/Core Core issues without another label help wanted adoptme

Comments

@djschny
Copy link
Contributor

djschny commented Aug 12, 2015

Performing a stats aggregation over a string field throws 500 error with an exception as opposed to a simplified error stating the the field specified is not valid for a stats aggregation.

I would expect a 400 for example since the client to fix their request before retrying it. Additionally it would help if the error message was more indicative of the problem as opposed to a SearchPhaseExecutionException. I would hope we should be able to detect this prior to performing the actual search.

GET /stack/_search?search_type=count
{
  "aggs": {
    "dateAggTest": {
      "stats": {
        "field": "title"
      }
    }
  }
}
{
   "error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[hjvyPMaiTgewDbpd9j67_A][stack][0]: ClassCastException[org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData cannot be cast to org.elasticsearch.index.fielddata.IndexNumericFieldData]}{[hjvyPMaiTgewDbpd9j67_A][stack][1]: ClassCastException[org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData cannot be cast to org.elasticsearch.index.fielddata.IndexNumericFieldData]}{[hjvyPMaiTgewDbpd9j67_A][stack][2]: ClassCastException[org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData cannot be cast to org.elasticsearch.index.fielddata.IndexNumericFieldData]}{[hjvyPMaiTgewDbpd9j67_A][stack][3]: ClassCastException[org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData cannot be cast to org.elasticsearch.index.fielddata.IndexNumericFieldData]}{[hjvyPMaiTgewDbpd9j67_A][stack][4]: ClassCastException[org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData cannot be cast to org.elasticsearch.index.fielddata.IndexNumericFieldData]}]",
   "status": 500
}
@clintongormley
Copy link

Agreed, should be a 400 - probably need a wider review of exceptions too

@xuzha
Copy link
Contributor

xuzha commented Aug 14, 2015

We should have a better error message here.

And should we just treat every ClassCastException is a 400 rather than 500? If user send correct request and get 400, OK, you find a bug we are going to fix it.

@jpountz
Copy link
Contributor

jpountz commented Aug 14, 2015

And should we just treat every ClassCastException is a 400 rather than 500? If user send correct request and get 400, OK, you find a bug we are going to fix it.

I don't think we can generalize that class-cast exceptions are user-input errors rather than internal errors. We should just better validate that fields have the expected type.

It might be harder with scripts as scripts can do pretty much anything, but I assume that if we can make it work well on fields, that would be a good start already.

@djschny
Copy link
Contributor Author

djschny commented Aug 14, 2015

+1 @jpountz, I would assume scripts to be out of scope. Not enough gain for the amount of work it would take to handle all cases, etc.

xuzha pushed a commit to xuzha/elasticsearch that referenced this issue Aug 15, 2015
Let stats aggregation returns 400 error when performed over an invalid field

closes elastic#12842
@lcawl lcawl added :Core/Infra/Core Core issues without another label and removed :Exceptions labels Feb 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/Aggregations Aggregations >bug :Core/Infra/Core Core issues without another label help wanted adoptme
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants