@Override protected void masterOperation(ListStoresActionRequest request, ClusterState state, ActionListener<ListStoresActionResponse> listener) throws Exception { String[] names = indexNameExpressionResolver.concreteIndexNames(state, new ClusterStateRequest().indices(IndexFeatureStore.DEFAULT_STORE, IndexFeatureStore.STORE_PREFIX + "*")); final MultiSearchRequestBuilder req = client.prepareMultiSearch(); final List<Tuple<String, Integer>> versions = new ArrayList<>(); Stream.of(names) .filter(IndexFeatureStore::isIndexStore) .map((s) -> clusterService.state().metaData().getIndices().get(s)) .filter(Objects::nonNull) .filter((im) -> STORE_VERSION_PROP.exists(im.getSettings())) .forEach((m) -> { req.add(countSearchRequest(m)); versions.add(tuple(m.getIndex().getName(),STORE_VERSION_PROP.get(m.getSettings()))); }); if (versions.isEmpty()) { listener.onResponse(new ListStoresActionResponse(Collections.emptyList())); } else { req.execute(wrap((r) -> listener.onResponse(toResponse(r, versions)), listener::onFailure)); } }
/** * Execute query request with filter and aggregations. * * @param queries * list of queries to execute * @return ES search response * @throws ODataApplicationException * if any error appeared during executing request */ public MultiSearchResponse executeRequest(List<SearchQuery> queries) throws ODataApplicationException { MultiSearchRequestBuilder multiSearchRequestBuilder = client.prepareMultiSearch(); for (SearchQuery query : queries) { Pagination pagination = query.getPagination(); SearchRequestBuilder requestBuilder = client.prepareSearch(query.getIndex()) .setTypes(query.getTypes()).setQuery(query.getQueryBuilder()); if (pagination != null) { List<Sort> orderBy = pagination.getOrderBy(); for (Sort sort : orderBy) { FieldSortBuilder sortQuery = SortBuilders.fieldSort(sort.getProperty()) .order(SortOrder.valueOf(sort.getDirection().toString())); requestBuilder.addSort(sortQuery); } requestBuilder.setSize(pagination.getTop()).setFrom(pagination.getSkip()); } Set<String> fields = query.getFields(); if (fields != null && !fields.isEmpty()) { requestBuilder.setFetchSource(fields.toArray(new String[fields.size()]), null); } multiSearchRequestBuilder.add(requestBuilder); } return executeRequest(multiSearchRequestBuilder); }
@Test public void testMultiSearchRequestBuilder() throws IOException { SuggestionsRestService tested = new SuggestionsRestService(); tested.searchClientService = Mockito.mock(SearchClientService.class); tested.log = Logger.getLogger("testlogger"); MultiSearchRequestBuilder msrb = new MultiSearchRequestBuilder(null); SearchRequestBuilder srbNGram = new SearchRequestBuilder(null); SearchRequestBuilder srbFuzzy = new SearchRequestBuilder(null); msrb = tested.getProjectMultiSearchRequestBuilder(msrb, tested.getProjectSearchNGramRequestBuilder(srbNGram, "JBoss", 5), tested.getProjectSearchFuzzyRequestBuilder(srbFuzzy, "JBoss", 5)); MultiSearchRequest msr = msrb.request(); Assert.assertEquals(2, msr.requests().size()); }
private static MultiSearchRequestBuilder msearch(IndicesOptions options, String... indices) { MultiSearchRequestBuilder multiSearchRequestBuilder = client().prepareMultiSearch(); if (options != null) { multiSearchRequestBuilder.setIndicesOptions(options); } return multiSearchRequestBuilder.add(client().prepareSearch(indices).setQuery(matchAllQuery())); }
public MultiSearchResponse executeSearch(Client elasticClient,RelatedItemSearch[] searches) { MultiSearchRequestBuilder multiSearch = elasticClient.prepareMultiSearch(); for(RelatedItemSearch search : searches) { if(search.getRelatedItemSearchType() == RelatedItemSearchType.FREQUENTLY_RELATED_WITH) { multiSearch.add(createFrequentlyRelatedContentSearch(search,elasticClient)); } } log.debug("executing search {} request(s)",searches.length); return multiSearch.execute().actionGet(searchTimeout, TimeUnit.MILLISECONDS); }
@Override public MultiSearchRequestBuilder prepareMultiSearch() { return new MultiSearchRequestBuilder(this, MultiSearchAction.INSTANCE); }
@Override public MultiSearchRequestBuilder prepareMultiSearch() { // TODO Auto-generated method stub return null; }
@Override public void execute(Tuple input) { _collector.ack(input); // this bolt can be connected to anything // we just want to trigger a new search when the input is a tick tuple if (!TupleUtils.isTick(input)) { return; } Status[] slist = new Status[] { Status.DISCOVERED, Status.ERROR, Status.FETCH_ERROR, Status.FETCHED, Status.REDIRECTION }; MultiSearchRequestBuilder multi = connection.getClient() .prepareMultiSearch(); // should be faster than running the aggregations // sent as a single multisearch for (Status s : slist) { SearchRequestBuilder request = connection.getClient() .prepareSearch(indexName).setTypes(docType).setFrom(0) .setSize(0).setExplain(false); request.setQuery(QueryBuilders.termQuery("status", s.name())); multi.add(request); } long start = System.currentTimeMillis(); MultiSearchResponse response = multi.get(); long end = System.currentTimeMillis(); LOG.info("Multiquery returned in {} msec", end - start); for (int i = 0; i < response.getResponses().length; i++) { SearchResponse res = response.getResponses()[i].getResponse(); long total = res.getHits().getTotalHits(); latestStatusCounts.put(slist[i].name(), total); } }
public void allReader(ElastisearchCrawlerMultipleHits crawler) throws Exception { try { MultiSearchResponse.Item[] items = Elasticsearch.withRetry(new ElasticsearchWithRetry<Item[]>() { public Item[] call(Client client) throws NoNodeAvailableException { MultiSearchRequestBuilder multisearchrequestbuilder = new MultiSearchRequestBuilder(client); for (int pos = 0; pos < queries.size(); pos++) { multisearchrequestbuilder.add(queries.get(pos).getRequest()); } return multisearchrequestbuilder.execute().actionGet().getResponses(); } }); SearchHit[] hits; SearchResponse response; for (int pos_response = 0; pos_response < items.length; pos_response++) { if (items[pos_response].isFailure()) { Loggers.ElasticSearch.warn("Search failed", new Exception(items[pos_response].getFailureMessage())); continue; } response = items[pos_response].getResponse(); if (response == null) { continue; } if (response.getHits() == null) { continue; } hits = response.getHits().hits(); if (hits.length == 0) { continue; } if (crawler.onMultipleResponse(response, Arrays.asList(hits)) == false) { return; } } } catch (IndexMissingException ime) { /** * No items == no callbacks */ Loggers.ElasticSearch.debug("Index missing", ime); return; } catch (SearchPhaseExecutionException e) { Loggers.ElasticSearch.debug("No datas", e); } }
/** * Performs multiple search requests. */ MultiSearchRequestBuilder prepareMultiSearch();