Package org.elasticsearch.search.fetch

Examples of org.elasticsearch.search.fetch.QueryFetchSearchResult


        QuerySearchResult queryResult = searchService.executeQueryPhase(searchRequest(searchSource().query(termQuery("name", "test1")), SearchType.QUERY_THEN_FETCH));
        assertThat(queryResult.topDocs().totalHits, equalTo(1));
    }

    @Test public void testDirectFetch() throws Exception {
        QueryFetchSearchResult queryFetchResult = searchService.executeFetchPhase(searchRequest(searchSource().query(termQuery("name", "test1")), SearchType.QUERY_AND_FETCH));
        assertThat(queryFetchResult.queryResult().topDocs().totalHits, equalTo(1));
        assertThat(queryFetchResult.fetchResult().hits().hits().length, equalTo(1));
        assertThat(queryFetchResult.fetchResult().hits().hits()[0].sourceAsString(), equalTo(source("1", "test1", 1)));
        assertThat(queryFetchResult.fetchResult().hits().hits()[0].id(), equalTo("1"));
        assertThat(queryFetchResult.fetchResult().hits().hits()[0].type(), equalTo("type1"));
    }
View Full Code Here


        Set<String> expectedIds = Sets.newHashSet("1", "2", "3", "4", "5");
        assertThat(idsLoaded, equalTo(expectedIds));
    }

    @Test public void testQueryAndFetch() throws Exception {
        QueryFetchSearchResult result = searchService.executeFetchPhase(searchRequest(searchSource().query(termQuery("name", "test1")), SearchType.QUERY_AND_FETCH));
        FetchSearchResult fetchResult = result.fetchResult();
        assertThat(fetchResult.hits().hits()[0].sourceAsString(), equalTo(source("1", "test1", 1)));
        assertThat(fetchResult.hits().hits()[0].id(), equalTo("1"));
        assertThat(fetchResult.hits().hits()[0].type(), equalTo("type1"));
    }
View Full Code Here

        assertThat(fetchResult.hits().hits()[0].id(), equalTo("1"));
        assertThat(fetchResult.hits().hits()[0].type(), equalTo("type1"));
    }

    @Test public void testQueryAndFetchIterateWithFrom() throws Exception {
        QueryFetchSearchResult result = searchService.executeFetchPhase(searchRequest(searchSource().query(matchAllQuery()).from(0).size(2).sort("age", SortOrder.DESC), SearchType.QUERY_AND_FETCH));
        assertThat(result.queryResult().topDocs().totalHits, equalTo(5));

        Set<String> idsLoaded = Sets.newHashSet();

        ShardDoc[] sortedShardList = searchPhaseController.sortDocs(newArrayList(result));
        Map<SearchShardTarget, QueryFetchSearchResult> queryResults = Maps.newHashMap();
        queryResults.put(result.queryResult().shardTarget(), result);
        InternalSearchResponse searchResponse = searchPhaseController.merge(sortedShardList, queryResults, queryResults);

        for (SearchHit hit : searchResponse.hits()) {
            idsLoaded.add(hit.id());
        }

        // iterate to the next 2
        result = searchService.executeFetchPhase(searchRequest(searchSource().query(matchAllQuery()).from(2).size(2).sort("age", SortOrder.DESC), SearchType.QUERY_AND_FETCH));
        assertThat(result.queryResult().topDocs().totalHits, equalTo(5));

        sortedShardList = searchPhaseController.sortDocs(newArrayList(result));
        queryResults = Maps.newHashMap();
        queryResults.put(result.queryResult().shardTarget(), result);
        searchResponse = searchPhaseController.merge(sortedShardList, queryResults, queryResults);

        for (SearchHit hit : searchResponse.hits()) {
            idsLoaded.add(hit.id());
        }
        result = searchService.executeFetchPhase(searchRequest(searchSource().query(matchAllQuery()).from(4).size(2).sort("age", SortOrder.DESC), SearchType.QUERY_AND_FETCH));
        assertThat(result.queryResult().topDocs().totalHits, equalTo(5));

        sortedShardList = searchPhaseController.sortDocs(newArrayList(result));
        queryResults = Maps.newHashMap();
        queryResults.put(result.queryResult().shardTarget(), result);
        searchResponse = searchPhaseController.merge(sortedShardList, queryResults, queryResults);

        for (SearchHit hit : searchResponse.hits()) {
            idsLoaded.add(hit.id());
        }
View Full Code Here

        }

        AggregatedDfs dfs = searchPhaseController.aggregateDfs(dfsResults);
        Map<SearchShardTarget, QueryFetchSearchResult> queryFetchResults = newHashMap();
        for (DfsSearchResult dfsResult : dfsResults) {
            QueryFetchSearchResult queryFetchResult = nodeToSearchService.get(dfsResult.shardTarget().nodeId()).executeFetchPhase(new QuerySearchRequest(dfsResult.id(), dfs));
            queryFetchResults.put(queryFetchResult.shardTarget(), queryFetchResult);
        }


        ShardDoc[] sortedShardList = searchPhaseController.sortDocs(queryFetchResults.values());
        SearchHits hits = searchPhaseController.merge(sortedShardList, queryFetchResults, queryFetchResults).hits();
View Full Code Here

        Map<SearchShardTarget, QueryFetchSearchResult> queryFetchResults = newHashMap();
        for (ShardIterator shardIt : clusterService.operationRouting().searchShards(clusterService.state(), new String[]{"test"}, new String[]{"test"}, null, null, null)) {
            for (ShardRouting shardRouting : shardIt.asUnordered()) {
                InternalSearchRequest searchRequest = searchRequest(shardRouting, sourceBuilder, SearchType.QUERY_AND_FETCH)
                        .scroll(new Scroll(new TimeValue(10, TimeUnit.MINUTES)));
                QueryFetchSearchResult queryFetchResult = nodeToSearchService.get(shardRouting.currentNodeId()).executeFetchPhase(searchRequest);
                queryFetchResults.put(queryFetchResult.shardTarget(), queryFetchResult);
            }
        }


        ShardDoc[] sortedShardList = searchPhaseController.sortDocs(queryFetchResults.values());
        SearchHits hits = searchPhaseController.merge(sortedShardList, queryFetchResults, queryFetchResults).hits();

        assertThat(hits.totalHits(), equalTo(100l));
        assertThat(hits.hits().length, equalTo(60)); // 60 results, with size 20, since we have 3 shards
        for (int i = 0; i < 60; i++) {
            SearchHit hit = hits.hits()[i];
//            System.out.println(hit.id() + " " + hit.explanation());
//            assertThat("id[" + hit.id() + "]", hit.id(), equalTo(Integer.toString(100 - i - 1)));
            assertThat("make sure we don't have duplicates", expectedIds.remove(hit.id()), notNullValue());
        }

        // scrolling with query+fetch is not perfect when it comes to dist sorting
        Map<SearchShardTarget, QueryFetchSearchResult> scrollQueryFetchResults = newHashMap();
        for (QueryFetchSearchResult searchResult : queryFetchResults.values()) {
            QueryFetchSearchResult queryFetchResult = nodeToSearchService.get(searchResult.shardTarget().nodeId()).executeFetchPhase(new InternalScrollSearchRequest(searchResult.id()).scroll(new Scroll(timeValueMinutes(10)))).result();
            scrollQueryFetchResults.put(queryFetchResult.shardTarget(), queryFetchResult);
        }
        queryFetchResults = scrollQueryFetchResults;

        sortedShardList = searchPhaseController.sortDocs(queryFetchResults.values());
        hits = searchPhaseController.merge(sortedShardList, queryFetchResults, queryFetchResults).hits();
View Full Code Here

            if (context.scroll() == null || context.fetchResult().hits().hits().length < context.size()) {
                freeContext(request.id());
            } else {
                contextProcessedSuccessfully(context);
            }
            return new ScrollQueryFetchSearchResult(new QueryFetchSearchResult(context.queryResult(), context.fetchResult()), context.shardTarget());
        } catch (RuntimeException e) {
            logger.trace("Scan phase failed", e);
            freeContext(context);
            throw e;
        } finally {
View Full Code Here

            if (context.scroll() == null) {
                freeContext(context.id());
            } else {
                contextProcessedSuccessfully(context);
            }
            return new QueryFetchSearchResult(context.queryResult(), context.fetchResult());
        } catch (RuntimeException e) {
            logger.trace("Fetch phase failed", e);
            freeContext(context);
            throw e;
        } finally {
View Full Code Here

            if (context.scroll() == null) {
                freeContext(request.id());
            } else {
                contextProcessedSuccessfully(context);
            }
            return new QueryFetchSearchResult(context.queryResult(), context.fetchResult());
        } catch (RuntimeException e) {
            logger.trace("Fetch phase failed", e);
            freeContext(context);
            throw e;
        } finally {
View Full Code Here

            if (context.scroll() == null) {
                freeContext(request.id());
            } else {
                contextProcessedSuccessfully(context);
            }
            return new ScrollQueryFetchSearchResult(new QueryFetchSearchResult(context.queryResult(), context.fetchResult()), context.shardTarget());
        } catch (RuntimeException e) {
            logger.trace("Fetch phase failed", e);
            freeContext(context);
            throw e;
        } finally {
View Full Code Here

    }

    public void sendExecuteFetch(DiscoveryNode node, final InternalSearchRequest request, final SearchServiceListener<QueryFetchSearchResult> listener) {
        if (clusterService.state().nodes().localNodeId().equals(node.id())) {
            try {
                QueryFetchSearchResult result = searchService.executeFetchPhase(request);
                listener.onResult(result);
            } catch (Exception e) {
                listener.onFailure(e);
            }
        } else {
            transportService.sendRequest(node, SearchQueryFetchTransportHandler.ACTION, request, new BaseTransportResponseHandler<QueryFetchSearchResult>() {

                @Override public QueryFetchSearchResult newInstance() {
                    return new QueryFetchSearchResult();
                }

                @Override public void handleResponse(QueryFetchSearchResult response) {
                    listener.onResult(response);
                }
View Full Code Here

TOP

Related Classes of org.elasticsearch.search.fetch.QueryFetchSearchResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.