From 8c1fe37e9265abdf889bd7f7c3fbc03186b98cc8 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Sat, 13 Feb 2016 08:57:32 +0100 Subject: [PATCH] Remove in-place rewriting of SearchSourceBuilder SearchSourceBuilder should be cloned when rewriting, the in-place rewrite is failing with local transport assertions. --- .../java/org/elasticsearch/search/SearchService.java | 3 --- .../search/builder/SearchSourceBuilder.java | 12 ------------ .../search/builder/SearchSourceBuilderTests.java | 10 ---------- 3 files changed, 25 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/SearchService.java b/core/src/main/java/org/elasticsearch/search/SearchService.java index a52589c8641..0d116f264b9 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchService.java +++ b/core/src/main/java/org/elasticsearch/search/SearchService.java @@ -533,9 +533,6 @@ public class SearchService extends AbstractLifecycleComponent imp DefaultSearchContext context = new DefaultSearchContext(idGenerator.incrementAndGet(), request, shardTarget, engineSearcher, indexService, indexShard, scriptService, pageCacheRecycler, bigArrays, threadPool.estimatedTimeInMillisCounter(), parseFieldMatcher, defaultSearchTimeout); SearchContext.setCurrent(context); try { - if (request.source() != null) { - request.source().rewrite(context.getQueryShardContext()); - } if (request.scroll() != null) { context.scrollContext(new ScrollContext()); context.scrollContext().scroll = request.scroll(); diff --git a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java index 99ee939d15b..e60e6c5a0a0 100644 --- a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java @@ -1435,16 +1435,4 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ && Objects.equals(profile, other.profile); } - /** - * Rewrites the internal query builders in-place - */ - public void rewrite(QueryRewriteContext rewriteContext) throws IOException { - if (queryBuilder != null) { - queryBuilder = QueryBuilder.rewriteQuery(queryBuilder, rewriteContext); - } - if (postQueryBuilder != null) { - postQueryBuilder = QueryBuilder.rewriteQuery(postQueryBuilder, rewriteContext); - } - } - } diff --git a/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java b/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java index 5321d732be9..93577325070 100644 --- a/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java @@ -488,14 +488,4 @@ public class SearchSourceBuilderTests extends ESTestCase { String query = "{ \"post_filter\": {} }"; assertParseSearchSource(builder, new BytesArray(query)); } - - public void testRewrite() throws IOException { - SearchSourceBuilder builder = new SearchSourceBuilder(); - builder.query(new BoolQueryBuilder()); - TermQueryBuilder tqb = new TermQueryBuilder("foo", "bar"); - builder.postFilter(new WrapperQueryBuilder(tqb.toString())); - builder.rewrite(new QueryRewriteContext(null, null, indicesQueriesRegistry)); - assertEquals(new MatchAllQueryBuilder(), builder.query()); - assertEquals(tqb, builder.postFilter()); - } }