Search in sources :

Example 6 with InternalSearchResponse

use of org.elasticsearch.search.internal.InternalSearchResponse in project elasticsearch by elastic.

the class SearchScrollQueryThenFetchAsyncAction method finishHim.

private void finishHim(SearchPhaseController.ReducedQueryPhase queryPhase) {
    try {
        final InternalSearchResponse internalResponse = searchPhaseController.merge(true, sortedShardDocs, queryPhase, fetchResults);
        String scrollId = null;
        if (request.scroll() != null) {
            scrollId = request.scrollId();
        }
        listener.onResponse(new SearchResponse(internalResponse, scrollId, this.scrollId.getContext().length, successfulOps.get(), buildTookInMillis(), buildShardFailures()));
    } catch (Exception e) {
        listener.onFailure(new ReduceSearchPhaseException("fetch", "inner finish failed", e, buildShardFailures()));
    }
}
Also used : InternalSearchResponse(org.elasticsearch.search.internal.InternalSearchResponse) InternalSearchResponse(org.elasticsearch.search.internal.InternalSearchResponse)

Example 7 with InternalSearchResponse

use of org.elasticsearch.search.internal.InternalSearchResponse in project elasticsearch by elastic.

the class ExpandSearchPhaseTests method testFailOneItemFailsEntirePhase.

public void testFailOneItemFailsEntirePhase() throws IOException {
    AtomicBoolean executedMultiSearch = new AtomicBoolean(false);
    SearchHits collapsedHits = new SearchHits(new SearchHit[] { new SearchHit(2, "ID", new Text("type"), Collections.emptyMap()), new SearchHit(3, "ID", new Text("type"), Collections.emptyMap()) }, 1, 1.0F);
    MockSearchPhaseContext mockSearchPhaseContext = new MockSearchPhaseContext(1);
    String collapseValue = randomBoolean() ? null : "boom";
    mockSearchPhaseContext.getRequest().source(new SearchSourceBuilder().collapse(new CollapseBuilder("someField").setInnerHits(new InnerHitBuilder().setName("foobarbaz"))));
    mockSearchPhaseContext.searchTransport = new SearchTransportService(Settings.builder().put("search.remote.connect", false).build(), null, null) {

        @Override
        void sendExecuteMultiSearch(MultiSearchRequest request, SearchTask task, ActionListener<MultiSearchResponse> listener) {
            assertTrue(executedMultiSearch.compareAndSet(false, true));
            InternalSearchResponse internalSearchResponse = new InternalSearchResponse(collapsedHits, null, null, null, false, null, 1);
            SearchResponse response = mockSearchPhaseContext.buildSearchResponse(internalSearchResponse, null);
            listener.onResponse(new MultiSearchResponse(new MultiSearchResponse.Item[] { new MultiSearchResponse.Item(null, new RuntimeException("boom")), new MultiSearchResponse.Item(response, null) }));
        }
    };
    SearchHits hits = new SearchHits(new SearchHit[] { new SearchHit(1, "ID", new Text("type"), Collections.singletonMap("someField", new SearchHitField("someField", Collections.singletonList(collapseValue)))), new SearchHit(2, "ID2", new Text("type"), Collections.singletonMap("someField", new SearchHitField("someField", Collections.singletonList(collapseValue)))) }, 1, 1.0F);
    InternalSearchResponse internalSearchResponse = new InternalSearchResponse(hits, null, null, null, false, null, 1);
    SearchResponse response = mockSearchPhaseContext.buildSearchResponse(internalSearchResponse, null);
    AtomicReference<SearchResponse> reference = new AtomicReference<>();
    ExpandSearchPhase phase = new ExpandSearchPhase(mockSearchPhaseContext, response, r -> new SearchPhase("test") {

        @Override
        public void run() throws IOException {
            reference.set(r);
        }
    });
    phase.run();
    assertThat(mockSearchPhaseContext.phaseFailure.get(), Matchers.instanceOf(RuntimeException.class));
    assertEquals("boom", mockSearchPhaseContext.phaseFailure.get().getMessage());
    assertNotNull(mockSearchPhaseContext.phaseFailure.get());
    assertNull(reference.get());
    assertEquals(0, mockSearchPhaseContext.phasesExecuted.get());
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) InnerHitBuilder(org.elasticsearch.index.query.InnerHitBuilder) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) SearchHits(org.elasticsearch.search.SearchHits) CollapseBuilder(org.elasticsearch.search.collapse.CollapseBuilder) Text(org.elasticsearch.common.text.Text) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) InternalSearchResponse(org.elasticsearch.search.internal.InternalSearchResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SearchHitField(org.elasticsearch.search.SearchHitField) InternalSearchResponse(org.elasticsearch.search.internal.InternalSearchResponse)

Example 8 with InternalSearchResponse

use of org.elasticsearch.search.internal.InternalSearchResponse in project elasticsearch by elastic.

the class ExpandSearchPhaseTests method testSkipPhase.

public void testSkipPhase() throws IOException {
    MockSearchPhaseContext mockSearchPhaseContext = new MockSearchPhaseContext(1);
    mockSearchPhaseContext.searchTransport = new SearchTransportService(Settings.builder().put("search.remote.connect", false).build(), null, null) {

        @Override
        void sendExecuteMultiSearch(MultiSearchRequest request, SearchTask task, ActionListener<MultiSearchResponse> listener) {
            fail("no collapsing here");
        }
    };
    SearchHits hits = new SearchHits(new SearchHit[] { new SearchHit(1, "ID", new Text("type"), Collections.singletonMap("someField", new SearchHitField("someField", Collections.singletonList(null)))), new SearchHit(2, "ID2", new Text("type"), Collections.singletonMap("someField", new SearchHitField("someField", Collections.singletonList(null)))) }, 1, 1.0F);
    InternalSearchResponse internalSearchResponse = new InternalSearchResponse(hits, null, null, null, false, null, 1);
    SearchResponse response = mockSearchPhaseContext.buildSearchResponse(internalSearchResponse, null);
    AtomicReference<SearchResponse> reference = new AtomicReference<>();
    ExpandSearchPhase phase = new ExpandSearchPhase(mockSearchPhaseContext, response, r -> new SearchPhase("test") {

        @Override
        public void run() throws IOException {
            reference.set(r);
        }
    });
    phase.run();
    mockSearchPhaseContext.assertNoFailure();
    assertNotNull(reference.get());
    assertEquals(1, mockSearchPhaseContext.phasesExecuted.get());
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) Text(org.elasticsearch.common.text.Text) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) InternalSearchResponse(org.elasticsearch.search.internal.InternalSearchResponse) SearchHitField(org.elasticsearch.search.SearchHitField) SearchHits(org.elasticsearch.search.SearchHits) InternalSearchResponse(org.elasticsearch.search.internal.InternalSearchResponse)

Aggregations

InternalSearchResponse (org.elasticsearch.search.internal.InternalSearchResponse)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Text (org.elasticsearch.common.text.Text)4 SearchHit (org.elasticsearch.search.SearchHit)4 SearchHits (org.elasticsearch.search.SearchHits)4 IOException (java.io.IOException)3 SearchHitField (org.elasticsearch.search.SearchHitField)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ScoreDoc (org.apache.lucene.search.ScoreDoc)2 InnerHitBuilder (org.elasticsearch.index.query.InnerHitBuilder)2 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)2 CollapseBuilder (org.elasticsearch.search.collapse.CollapseBuilder)2 ArrayList (java.util.ArrayList)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 TestUtil.randomSimpleString (org.apache.lucene.util.TestUtil.randomSimpleString)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 TimeValue (org.elasticsearch.common.unit.TimeValue)1 AbstractRunnable (org.elasticsearch.common.util.concurrent.AbstractRunnable)1 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1