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

NullPointer on from parameter with negative value and 500 code instead of 400 error #23324

Closed
gilfernandes opened this issue Feb 23, 2017 · 2 comments
Assignees
Labels
>bug :Search/Search Search-related issues that do not fall into other categories

Comments

@gilfernandes
Copy link

gilfernandes commented Feb 23, 2017

I have tried to fire a silly request to ElastiSearch 5.1.1:

GET products/_search

{
  **"from": -2**,
  "size": 100, 
  "query": {
    "match": {
      "productName": "soy sauce"
    }
  },
  "sort": [
    {
      "customerRating": {
        "order": "desc"
      }
    },
    "_score",
    {
      "price" : {
        "order": "asc"
      }
    }
  ]
}

and got this:

{
  "error": {
    "root_cause": [],
    "type": "reduce_search_phase_exception",
    "reason": "[reduce] ",
    "phase": "query",
    "grouped": true,
    "failed_shards": [],
    "caused_by": {
      "type": "null_pointer_exception",
      "reason": null
    }
  },
  "status": 503
}

I had expected a 400 (user error) and a meaningful error message, like e.g: from parameter cannot be negative.

@cbuescher cbuescher added the :Search/Search Search-related issues that do not fall into other categories label Feb 24, 2017
@cbuescher
Copy link
Member

I agree we should catch this earlier. I just reproduced this on 5.1.2. and there I get an ArrayIndexOutOfBoundsException from

java.lang.ArrayIndexOutOfBoundsException: -2
	at org.elasticsearch.action.search.SearchPhaseController.sortDocs(SearchPhaseController.java:214) ~[elasticsearch-5.1.2.jar:5.1.2]
	at org.elasticsearch.action.search.SearchQueryThenFetchAsyncAction.moveToSecondPhase(SearchQueryThenFetchAsyncAction.java:80) ~[elasticsearch-5.1.2.jar:5.1.2]

I think we should reject negative from values already in SearchSourceBuilder, which would mean that errors would be triggered either on the client side or the coordinating node.

@cbuescher cbuescher added the >bug label Feb 24, 2017
@cbuescher cbuescher self-assigned this Feb 24, 2017
cbuescher added a commit to cbuescher/elasticsearch that referenced this issue Feb 24, 2017
This prevents later errors like the one reported in elastic#23324 and throws an
IllegalArgumentException early instead.
cbuescher added a commit that referenced this issue Feb 27, 2017
This prevents later errors like the one reported in #23324 and throws an
IllegalArgumentException early instead.
cbuescher added a commit that referenced this issue Feb 27, 2017
This prevents later errors like the one reported in #23324 and throws an
IllegalArgumentException early instead.
@cbuescher
Copy link
Member

Closed by #23358

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

No branches or pull requests

2 participants