From 45a1b447599909a294ba63887bd91789c2e9b772 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Fri, 11 Apr 2014 17:33:35 +0700 Subject: [PATCH] Each search request should use a new InternalSearchResponse instance even in case when all shards return no hits. The InternalSearchResponse may get modified afterwards, so a new instance required at all times. --- rest-api-spec/test/scroll/11_clear.yaml | 5 ----- .../action/search/type/TransportSearchTypeAction.java | 2 +- .../search/controller/SearchPhaseController.java | 2 +- .../search/internal/InternalSearchResponse.java | 6 ++++-- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/rest-api-spec/test/scroll/11_clear.yaml b/rest-api-spec/test/scroll/11_clear.yaml index f8c8a4493b0..12cf760b418 100644 --- a/rest-api-spec/test/scroll/11_clear.yaml +++ b/rest-api-spec/test/scroll/11_clear.yaml @@ -1,9 +1,4 @@ --- -setup: - - skip: - version: 0 - 999 - reason: This test some impacts other tests ---- "Clear scroll": - do: indices.create: diff --git a/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java b/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java index 325ac54717f..d29d82207f3 100644 --- a/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java +++ b/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java @@ -140,7 +140,7 @@ public abstract class TransportSearchTypeAction extends TransportAction> fetchResults = fetchResultsArr.asList(); if (queryResults.isEmpty()) { - return InternalSearchResponse.EMPTY; + return InternalSearchResponse.empty(); } QuerySearchResult firstResult = queryResults.get(0).value.queryResult(); diff --git a/src/main/java/org/elasticsearch/search/internal/InternalSearchResponse.java b/src/main/java/org/elasticsearch/search/internal/InternalSearchResponse.java index 273c5bd9013..c48ad7c0930 100644 --- a/src/main/java/org/elasticsearch/search/internal/InternalSearchResponse.java +++ b/src/main/java/org/elasticsearch/search/internal/InternalSearchResponse.java @@ -40,6 +40,10 @@ import static org.elasticsearch.search.internal.InternalSearchHits.readSearchHit */ public class InternalSearchResponse implements Streamable, ToXContent { + public static InternalSearchResponse empty() { + return new InternalSearchResponse(new InternalSearchHits(new InternalSearchHit[0], 0, 0), null, null, null, false); + } + private InternalSearchHits hits; private InternalFacets facets; @@ -50,8 +54,6 @@ public class InternalSearchResponse implements Streamable, ToXContent { private boolean timedOut; - public static final InternalSearchResponse EMPTY = new InternalSearchResponse(new InternalSearchHits(new InternalSearchHit[0], 0, 0), null, null, null, false); - private InternalSearchResponse() { }