Error with search_after with java


(Ayshwarya Sree) #1

hi,
i am using elastic search to produce results for a index based on a sort parameter.
Now i want to use a search_after to retrive fewer records.
Search after gets its record from the previous result last hit.

for example i want to get all records of age 20 sorted by account number(my unique field) then feild is age
text is 20
sort_param= account_number
last hit is the hit.getSortValues() of the last record

this is the code i wrote for the above

SearchResponse sr = ts.prepareSearch("acc").
				setQuery(QueryBuilders.boolQuery().must(QueryBuilders.matchQuery(field.toLowerCase(),text))).
				setSize(this.size)
				.addSort(SortBuilders.fieldSort(sort_param).order(SortOrder.ASC).unmappedType(sort_param.getClass().getName()).missing("_last"))
				.searchAfter(lastHit)
				.get();

this is the error i am getting .

Failed to execute phase [query], all shards failed; shardFailures {[mksyIC4PQWa4WiA5eJO4Fg][acc][0]: RemoteTransportException[[mksyIC4][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[Sort must contain at least one field.]; }RemoteTransportException[[mksyIC4][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[Sort must contain at least one field.]; }RemoteTransportException[[mksyIC4][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[Sort must contain at least one field.]; }RemoteTransportException[[mksyIC4][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[Sort must contain at least one field.]; }RemoteTransportException[[mksyIC4][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[Sort must contain at least one field.]; }
	at org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseFailure(AbstractSearchAsyncAction.java:274)
	at org.elasticsearch.action.search.AbstractSearchAsyncAction.executeNextPhase(AbstractSearchAsyncAction.java:132)
	at org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseDone(AbstractSearchAsyncAction.java:243)
	at org.elasticsearch.action.search.InitialSearchPhase.onShardFailure(InitialSearchPhase.java:107)
	at org.elasticsearch.action.search.InitialSearchPhase.access$100(InitialSearchPhase.java:49)
	at org.elasticsearch.action.search.InitialSearchPhase$2.lambda$onFailure$1(InitialSearchPhase.java:217)
	at org.elasticsearch.action.search.InitialSearchPhase.maybeFork(InitialSearchPhase.java:171)
	at org.elasticsearch.action.search.InitialSearchPhase.access$000(InitialSearchPhase.java:49)
	at org.elasticsearch.action.search.InitialSearchPhase$2.onFailure(InitialSearchPhase.java:217)
	at org.elasticsearch.action.search.SearchExecutionStatsCollector.onFailure(SearchExecutionStatsCollector.java:73)
	at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:51)
	at org.elasticsearch.action.search.SearchTransportService$ConnectionCountingHandler.handleException(SearchTransportService.java:531)
	at org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.java:1056)
	at org.elasticsearch.transport.TransportService$DirectResponseChannel.processException(TransportService.java:1149)
	at org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1133)
	at org.elasticsearch.transport.TaskTransportChannel.sendResponse(TaskTransportChannel.java:66)
	at org.elasticsearch.action.search.SearchTransportService$6$1.onFailure(SearchTransportService.java:389)
	at org.elasticsearch.search.SearchService$2.onFailure(SearchService.java:318)
	at org.elasticsearch.search.SearchService$2.onResponse(SearchService.java:312)
	at org.elasticsearch.search.SearchService$2.onResponse(SearchService.java:306)
	at org.elasticsearch.search.SearchService$3.doRun(SearchService.java:996)
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:637)
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
	at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:41)
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: NotSerializableExceptionWrapper[: Sort must contain at least one field.]; nested: IllegalArgumentException[Sort must contain at least one field.];
	at org.elasticsearch.ElasticsearchException.guessRootCauses(ElasticsearchException.java:618)
	at org.elasticsearch.action.search.SearchPhaseExecutionException.guessRootCauses(SearchPhaseExecutionException.java:170)
	at org.elasticsearch.action.search.SearchPhaseExecutionException.getCause(SearchPhaseExecutionException.java:111)
	at org.elasticsearch.ElasticsearchException.writeTo(ElasticsearchException.java:285)
	at org.elasticsearch.action.search.SearchPhaseExecutionException.writeTo(SearchPhaseExecutionException.java:61)
	at org.elasticsearch.common.io.stream.StreamOutput.writeException(StreamOutput.java:864)
	at org.elasticsearch.ElasticsearchException.writeTo(ElasticsearchException.java:285)
	at org.elasticsearch.transport.ActionTransportException.writeTo(ActionTransportException.java:59)
	at org.elasticsearch.common.io.stream.StreamOutput.writeException(StreamOutput.java:864)
	at org.elasticsearch.transport.TcpTransport.sendErrorResponse(TcpTransport.java:1149)
	at org.elasticsearch.transport.TcpTransportChannel.sendResponse(TcpTransportChannel.java:71)
	at org.elasticsearch.transport.TaskTransportChannel.sendResponse(TaskTransportChannel.java:66)
	at org.elasticsearch.action.support.HandledTransportAction$TransportHandler$1.onFailure(HandledTransportAction.java:77)
	at org.elasticsearch.action.search.AbstractSearchAsyncAction.raisePhaseFailure(AbstractSearchAsyncAction.java:222)
	... 28 more
Caused by: java.lang.IllegalArgumentException: Sort must contain at least one field.
	at org.elasticsearch.search.searchafter.SearchAfterBuilder.buildFieldDoc(SearchAfterBuilder.java:107)
	at org.elasticsearch.search.SearchService.parseSource(SearchService.java:821)
	at org.elasticsearch.search.SearchService.createContext(SearchService.java:552)
	at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:528)
	at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:324)
	at org.elasticsearch.search.SearchService$2.onResponse(SearchService.java:310)
	... 9 more

(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.