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

ES 5.x JAVA API SortBuilder throws an exception. #22075

Closed
muteri opened this Issue Dec 9, 2016 · 4 comments

Comments

Projects
None yet
3 participants
@muteri

muteri commented Dec 9, 2016

Elasticsearch version: 5.1.1

Plugins installed: []

JVM version: 1.8.0_74

OS version:

Description of the problem including expected versus actual behavior:

Since ES 5.0 we have an issue when using sortBuilders from java API.
If we use Builder.addSort(SortBuilder) we got an error, if we replace by Builder.addSort(field, SortOrder) everything is fine.
In both case the generated json Query is the same and is working fine with sense. The issue seems only occurs from JAVA APi.

The sort was on _sort field.

Steps to reproduce:

  1. Create a search, with highlight, add Track_scores=true, and addsort(SortBuilder) with _score
@cbuescher

This comment has been minimized.

Show comment
Hide comment
@cbuescher

cbuescher Dec 9, 2016

Member

Can you add the exception you are seeing and if possible also the java code you use when this happens?

Member

cbuescher commented Dec 9, 2016

Can you add the exception you are seeing and if possible also the java code you use when this happens?

@muteri

This comment has been minimized.

Show comment
Hide comment
@muteri

muteri Dec 9, 2016

The exception is :

org.elasticsearch.action.search.SearchPhaseExecutionException: all shards failed
	at org.elasticsearch.action.search.AbstractSearchAsyncAction.onFirstPhaseResult(AbstractSearchAsyncAction.java:204) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.action.search.AbstractSearchAsyncAction$1.onFailure(AbstractSearchAsyncAction.java:139) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:51) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.java:984) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.transport.TransportService$DirectResponseChannel.processException(TransportService.java:1091) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1069) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.transport.DelegatingTransportChannel.sendResponse(DelegatingTransportChannel.java:68) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.transport.RequestHandlerRegistry$TransportChannelWrapper.sendResponse(RequestHandlerRegistry.java:123) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler.lambda$messageReceived$0(SecurityServerTransportInterceptor.java:197) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler.lambda$messageReceived$1(SecurityServerTransportInterceptor.java:210) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.common.util.concurrent.EsExecutors$1.execute(EsExecutors.java:109) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler.lambda$messageReceived$2(SecurityServerTransportInterceptor.java:246) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:53) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.ServerTransportFilter$NodeProfile.lambda$null$0(ServerTransportFilter.java:135) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authz.AuthorizationUtils$AsyncAuthorizer.maybeRun(AuthorizationUtils.java:131) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authz.AuthorizationUtils$AsyncAuthorizer.setRunAsRoles(AuthorizationUtils.java:125) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authz.AuthorizationUtils$AsyncAuthorizer.authorize(AuthorizationUtils.java:113) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.ServerTransportFilter$NodeProfile.lambda$inbound$1(ServerTransportFilter.java:137) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:53) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService$Authenticator.lambda$authenticateAsync$0(AuthenticationService.java:180) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService$Authenticator.lambda$lookForExistingAuthentication$2(AuthenticationService.java:199) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService$Authenticator.lookForExistingAuthentication(AuthenticationService.java:211) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService$Authenticator.authenticateAsync(AuthenticationService.java:178) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService$Authenticator.access$000(AuthenticationService.java:140) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService.authenticate(AuthenticationService.java:112) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.ServerTransportFilter$NodeProfile.inbound(ServerTransportFilter.java:131) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler.messageReceived(SecurityServerTransportInterceptor.java:253) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.transport.TransportService$6.doRun(TransportService.java:577) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:527) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-5.1.1.jar:5.1.1]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_74]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_74]
	at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_74]
Caused by: org.elasticsearch.transport.RemoteTransportException: [instance-0000000002][10.74.160.66:19642][indices:data/read/search[phase/query]]
Caused by: org.elasticsearch.index.query.QueryShardException: No mapping found for [_score] in order to sort on
	at org.elasticsearch.search.sort.FieldSortBuilder.build(FieldSortBuilder.java:262) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.search.sort.SortBuilder.buildSort(SortBuilder.java:156) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.search.SearchService.parseSource(SearchService.java:709) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.search.SearchService.createContext(SearchService.java:553) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:529) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:264) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.action.search.SearchTransportService$6.messageReceived(SearchTransportService.java:300) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.action.search.SearchTransportService$6.messageReceived(SearchTransportService.java:297) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler.lambda$messageReceived$1(SecurityServerTransportInterceptor.java:208) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.common.util.concurrent.EsExecutors$1.execute(EsExecutors.java:109) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler.lambda$messageReceived$2(SecurityServerTransportInterceptor.java:246) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:53) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.ServerTransportFilter$NodeProfile.lambda$null$0(ServerTransportFilter.java:135) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authz.AuthorizationUtils$AsyncAuthorizer.maybeRun(AuthorizationUtils.java:131) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authz.AuthorizationUtils$AsyncAuthorizer.setRunAsRoles(AuthorizationUtils.java:125) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authz.AuthorizationUtils$AsyncAuthorizer.authorize(AuthorizationUtils.java:113) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.ServerTransportFilter$NodeProfile.lambda$inbound$1(ServerTransportFilter.java:137) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:53) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService$Authenticator.lambda$authenticateAsync$0(AuthenticationService.java:180) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService$Authenticator.lambda$lookForExistingAuthentication$2(AuthenticationService.java:199) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService$Authenticator.lookForExistingAuthentication(AuthenticationService.java:211) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService$Authenticator.authenticateAsync(AuthenticationService.java:178) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService$Authenticator.access$000(AuthenticationService.java:140) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService.authenticate(AuthenticationService.java:112) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.ServerTransportFilter$NodeProfile.inbound(ServerTransportFilter.java:131) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler.messageReceived(SecurityServerTransportInterceptor.java:253) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.transport.TransportService$6.doRun(TransportService.java:577) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:527) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-5.1.1.jar:5.1.1]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_74]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_74]
	at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_74]

You can use this sample code to reproduce :

`SearchRequestBuilder builder = client.prepareSearch("g_contents").setVersion(true);

	builder.setTypes("g_content");

	HighlightBuilder highlightBuilder = new HighlightBuilder().field("fulltext.indexed_text", 75, 3);
	highlightBuilder.requireFieldMatch(false);
	builder.highlighter(highlightBuilder);
	builder.setTrackScores(true);

	BoolQueryBuilder filteredQuery = QueryBuilders.boolQuery();
	filteredQuery.should(QueryBuilders.termQuery("_all", "day"));

	builder.setQuery(filteredQuery);

	builder.setExplain(false);

	builder.setFrom(0).setSize(100);


	SortBuilder sb = SortBuilders.fieldSort("_score");
	sb.order(SortOrder.DESC);
	builder.addSort(sb);


	SearchResponse searchResponse;

	searchResponse = builder.get();`

muteri commented Dec 9, 2016

The exception is :

org.elasticsearch.action.search.SearchPhaseExecutionException: all shards failed
	at org.elasticsearch.action.search.AbstractSearchAsyncAction.onFirstPhaseResult(AbstractSearchAsyncAction.java:204) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.action.search.AbstractSearchAsyncAction$1.onFailure(AbstractSearchAsyncAction.java:139) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:51) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.java:984) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.transport.TransportService$DirectResponseChannel.processException(TransportService.java:1091) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1069) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.transport.DelegatingTransportChannel.sendResponse(DelegatingTransportChannel.java:68) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.transport.RequestHandlerRegistry$TransportChannelWrapper.sendResponse(RequestHandlerRegistry.java:123) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler.lambda$messageReceived$0(SecurityServerTransportInterceptor.java:197) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler.lambda$messageReceived$1(SecurityServerTransportInterceptor.java:210) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.common.util.concurrent.EsExecutors$1.execute(EsExecutors.java:109) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler.lambda$messageReceived$2(SecurityServerTransportInterceptor.java:246) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:53) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.ServerTransportFilter$NodeProfile.lambda$null$0(ServerTransportFilter.java:135) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authz.AuthorizationUtils$AsyncAuthorizer.maybeRun(AuthorizationUtils.java:131) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authz.AuthorizationUtils$AsyncAuthorizer.setRunAsRoles(AuthorizationUtils.java:125) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authz.AuthorizationUtils$AsyncAuthorizer.authorize(AuthorizationUtils.java:113) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.ServerTransportFilter$NodeProfile.lambda$inbound$1(ServerTransportFilter.java:137) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:53) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService$Authenticator.lambda$authenticateAsync$0(AuthenticationService.java:180) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService$Authenticator.lambda$lookForExistingAuthentication$2(AuthenticationService.java:199) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService$Authenticator.lookForExistingAuthentication(AuthenticationService.java:211) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService$Authenticator.authenticateAsync(AuthenticationService.java:178) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService$Authenticator.access$000(AuthenticationService.java:140) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService.authenticate(AuthenticationService.java:112) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.ServerTransportFilter$NodeProfile.inbound(ServerTransportFilter.java:131) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler.messageReceived(SecurityServerTransportInterceptor.java:253) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.transport.TransportService$6.doRun(TransportService.java:577) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:527) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-5.1.1.jar:5.1.1]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_74]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_74]
	at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_74]
Caused by: org.elasticsearch.transport.RemoteTransportException: [instance-0000000002][10.74.160.66:19642][indices:data/read/search[phase/query]]
Caused by: org.elasticsearch.index.query.QueryShardException: No mapping found for [_score] in order to sort on
	at org.elasticsearch.search.sort.FieldSortBuilder.build(FieldSortBuilder.java:262) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.search.sort.SortBuilder.buildSort(SortBuilder.java:156) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.search.SearchService.parseSource(SearchService.java:709) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.search.SearchService.createContext(SearchService.java:553) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:529) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:264) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.action.search.SearchTransportService$6.messageReceived(SearchTransportService.java:300) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.action.search.SearchTransportService$6.messageReceived(SearchTransportService.java:297) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler.lambda$messageReceived$1(SecurityServerTransportInterceptor.java:208) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.common.util.concurrent.EsExecutors$1.execute(EsExecutors.java:109) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler.lambda$messageReceived$2(SecurityServerTransportInterceptor.java:246) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:53) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.ServerTransportFilter$NodeProfile.lambda$null$0(ServerTransportFilter.java:135) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authz.AuthorizationUtils$AsyncAuthorizer.maybeRun(AuthorizationUtils.java:131) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authz.AuthorizationUtils$AsyncAuthorizer.setRunAsRoles(AuthorizationUtils.java:125) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authz.AuthorizationUtils$AsyncAuthorizer.authorize(AuthorizationUtils.java:113) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.ServerTransportFilter$NodeProfile.lambda$inbound$1(ServerTransportFilter.java:137) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:53) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService$Authenticator.lambda$authenticateAsync$0(AuthenticationService.java:180) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService$Authenticator.lambda$lookForExistingAuthentication$2(AuthenticationService.java:199) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService$Authenticator.lookForExistingAuthentication(AuthenticationService.java:211) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService$Authenticator.authenticateAsync(AuthenticationService.java:178) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService$Authenticator.access$000(AuthenticationService.java:140) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.authc.AuthenticationService.authenticate(AuthenticationService.java:112) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.ServerTransportFilter$NodeProfile.inbound(ServerTransportFilter.java:131) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler.messageReceived(SecurityServerTransportInterceptor.java:253) ~[x-pack-api-5.1.1.jar:5.1.1]
	at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.transport.TransportService$6.doRun(TransportService.java:577) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:527) ~[elasticsearch-5.1.1.jar:5.1.1]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-5.1.1.jar:5.1.1]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_74]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_74]
	at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_74]

You can use this sample code to reproduce :

`SearchRequestBuilder builder = client.prepareSearch("g_contents").setVersion(true);

	builder.setTypes("g_content");

	HighlightBuilder highlightBuilder = new HighlightBuilder().field("fulltext.indexed_text", 75, 3);
	highlightBuilder.requireFieldMatch(false);
	builder.highlighter(highlightBuilder);
	builder.setTrackScores(true);

	BoolQueryBuilder filteredQuery = QueryBuilders.boolQuery();
	filteredQuery.should(QueryBuilders.termQuery("_all", "day"));

	builder.setQuery(filteredQuery);

	builder.setExplain(false);

	builder.setFrom(0).setSize(100);


	SortBuilder sb = SortBuilders.fieldSort("_score");
	sb.order(SortOrder.DESC);
	builder.addSort(sb);


	SearchResponse searchResponse;

	searchResponse = builder.get();`
@cbuescher

This comment has been minimized.

Show comment
Hide comment
@cbuescher

cbuescher Dec 9, 2016

Member

SortBuilder sb = SortBuilders.fieldSort("_score");

@muteri the problem here is you are trying to sort on a field called "_score" which doesn't exist in your document (not the _score field in the search respone). You should use SortBuilder sb = SortBuilders.scoreSort(); to get a ScoreSortBuilder that is specialized for that. When using the `SearchRequest#addSort(field, SortOrder)" like you mentioned above we check the field name, recognize its a "special" field and use the ScoreSortBuilder. When you explicitely specify a field score sorting we assume you use a document field name, hence the problem you are seeing. Can you check if this if this solves your problem?

Member

cbuescher commented Dec 9, 2016

SortBuilder sb = SortBuilders.fieldSort("_score");

@muteri the problem here is you are trying to sort on a field called "_score" which doesn't exist in your document (not the _score field in the search respone). You should use SortBuilder sb = SortBuilders.scoreSort(); to get a ScoreSortBuilder that is specialized for that. When using the `SearchRequest#addSort(field, SortOrder)" like you mentioned above we check the field name, recognize its a "special" field and use the ScoreSortBuilder. When you explicitely specify a field score sorting we assume you use a document field name, hence the problem you are seeing. Can you check if this if this solves your problem?

@muteri

This comment has been minimized.

Show comment
Hide comment
@muteri

muteri Dec 15, 2016

@cbuescher sorry for the delayed answer, you're right the issue was coming from "_score". With .scoreSort() everything works fine. Thanks a lot.

muteri commented Dec 15, 2016

@cbuescher sorry for the delayed answer, you're right the issue was coming from "_score". With .scoreSort() everything works fine. Thanks a lot.

@muteri muteri closed this Dec 15, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment