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

Unhandled query size parameter #22530

Closed
gmoskovicz opened this issue Jan 10, 2017 · 2 comments
Closed

Unhandled query size parameter #22530

gmoskovicz opened this issue Jan 10, 2017 · 2 comments
Assignees
Labels
>bug good first issue low hanging fruit help wanted adoptme :Search/Search Search-related issues that do not fall into other categories

Comments

@gmoskovicz
Copy link
Contributor

gmoskovicz commented Jan 10, 2017

Elasticsearch version: ES 5.x

Plugins installed: none

JVM version: Any

OS version: Any

[1] Using -1 for the size returns top 10 results

POST /_search
{
  "size": -1
}

[2] Using any number <-1 returns an unhandled Lucene error:

POST /_search
{
  "size": -2
}


# Result


[2017-01-10T13:30:28,890][DEBUG][o.e.a.s.TransportSearchAction] [oZ4lS-x] All shards failed for phase: [query]
org.elasticsearch.transport.RemoteTransportException: [oZ4lS-x][127.0.0.1:9300][indices:data/read/search[phase/query]]
Caused by: org.elasticsearch.search.query.QueryPhaseExecutionException: Query Failed [Failed to execute main query]
	at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:405) ~[elasticsearch-5.1.0.jar:5.1.0]
	at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:106) ~[elasticsearch-5.1.0.jar:5.1.0]
	at org.elasticsearch.search.SearchService.loadOrExecuteQueryPhase(SearchService.java:259) ~[elasticsearch-5.1.0.jar:5.1.0]
	at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:273) ~[elasticsearch-5.1.0.jar:5.1.0]
	at org.elasticsearch.action.search.SearchTransportService$6.messageReceived(SearchTransportService.java:300) ~[elasticsearch-5.1.0.jar:5.1.0]
	at org.elasticsearch.action.search.SearchTransportService$6.messageReceived(SearchTransportService.java:297) ~[elasticsearch-5.1.0.jar:5.1.0]
	at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) ~[elasticsearch-5.1.0.jar:5.1.0]
	at org.elasticsearch.transport.TransportService$6.doRun(TransportService.java:577) [elasticsearch-5.1.0.jar:5.1.0]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:527) [elasticsearch-5.1.0.jar:5.1.0]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-5.1.0.jar:5.1.0]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_45]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_45]
	at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45]
Caused by: java.lang.IllegalArgumentException: numHits must be > 0; please use TotalHitCountCollector if you just need the total hit count
	at org.apache.lucene.search.TopScoreDocCollector.create(TopScoreDocCollector.java:170) ~[lucene-core-6.3.0.jar:6.3.0 a66a44513ee8191e25b477372094bfa846450316 - shalin - 2016-11-02 19:47:11]
	at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:219) ~[elasticsearch-5.1.0.jar:5.1.0]
	at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:106) ~[elasticsearch-5.1.0.jar:5.1.0]
	at org.elasticsearch.search.SearchService.loadOrExecuteQueryPhase(SearchService.java:259) ~[elasticsearch-5.1.0.jar:5.1.0]
	at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:273) ~[elasticsearch-5.1.0.jar:5.1.0]
	at org.elasticsearch.action.search.SearchTransportService$6.messageReceived(SearchTransportService.java:300) ~[elasticsearch-5.1.0.jar:5.1.0]
	at org.elasticsearch.action.search.SearchTransportService$6.messageReceived(SearchTransportService.java:297) ~[elasticsearch-5.1.0.jar:5.1.0]
	at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) ~[elasticsearch-5.1.0.jar:5.1.0]
	at org.elasticsearch.transport.TransportService$6.doRun(TransportService.java:577) ~[elasticsearch-5.1.0.jar:5.1.0]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:527) ~[elasticsearch-5.1.0.jar:5.1.0]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-5.1.0.jar:5.1.0]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[?:1.8.0_45]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[?:1.8.0_45]
	at java.lang.Thread.run(Thread.java:745) ~[?:1.8.0_45]

I think that the QueryPhase class should catch this before being an exception, so we avoid the exception thrown by TopScoreDocCollector. In other words, any number below 0 should return a custom Elasticsearch exception.

Also, reading the code i don't understand why -1 is just handled correctly.

@clintongormley clintongormley added :Search/Search Search-related issues that do not fall into other categories help wanted adoptme >bug good first issue low hanging fruit labels Jan 10, 2017
@makeyang
Copy link
Contributor

makeyang commented Jan 12, 2017

@gmoskovicz because -1 is taken as not set and then it will be set to default value.

@makeyang
Copy link
Contributor

@clintongormley I give a pull request to fix this issue. it is: #22579
can you please help to review it? thanks

@colings86 colings86 self-assigned this Jun 26, 2017
colings86 added a commit that referenced this issue Jul 4, 2017
* Adds check for negative search request size

This change adds a check to `SearchSourceBuilder` to throw and exception if the size set on it is set to a negative value.

Closes #22530

* fix error in reindex

* update re-index tests

* Addresses review comment

* Fixed tests

* Added random negative size test

* Fixes test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug good first issue low hanging fruit help wanted adoptme :Search/Search Search-related issues that do not fall into other categories
Projects
None yet
Development

No branches or pull requests

4 participants