本文整理汇总了Java中org.elasticsearch.action.search.MultiSearchRequestBuilder类的典型用法代码示例。如果您正苦于以下问题:Java MultiSearchRequestBuilder类的具体用法?Java MultiSearchRequestBuilder怎么用?Java MultiSearchRequestBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MultiSearchRequestBuilder类属于org.elasticsearch.action.search包,在下文中一共展示了MultiSearchRequestBuilder类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: masterOperation
import org.elasticsearch.action.search.MultiSearchRequestBuilder; //导入依赖的package包/类
@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));
}
}
示例2: executeRequest
import org.elasticsearch.action.search.MultiSearchRequestBuilder; //导入依赖的package包/类
/**
* 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);
}
示例3: testMultiSearchRequestBuilder
import org.elasticsearch.action.search.MultiSearchRequestBuilder; //导入依赖的package包/类
@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());
}
示例4: msearch
import org.elasticsearch.action.search.MultiSearchRequestBuilder; //导入依赖的package包/类
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()));
}
示例5: executeSearch
import org.elasticsearch.action.search.MultiSearchRequestBuilder; //导入依赖的package包/类
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);
}
示例6: prepareMultiSearch
import org.elasticsearch.action.search.MultiSearchRequestBuilder; //导入依赖的package包/类
@Override
public MultiSearchRequestBuilder prepareMultiSearch() {
return new MultiSearchRequestBuilder(this, MultiSearchAction.INSTANCE);
}
示例7: prepareMultiSearch
import org.elasticsearch.action.search.MultiSearchRequestBuilder; //导入依赖的package包/类
@Override
public MultiSearchRequestBuilder prepareMultiSearch() {
// TODO Auto-generated method stub
return null;
}
示例8: execute
import org.elasticsearch.action.search.MultiSearchRequestBuilder; //导入依赖的package包/类
@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);
}
}
示例9: allReader
import org.elasticsearch.action.search.MultiSearchRequestBuilder; //导入依赖的package包/类
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);
}
}
示例10: prepareMultiSearch
import org.elasticsearch.action.search.MultiSearchRequestBuilder; //导入依赖的package包/类
/**
* Performs multiple search requests.
*/
MultiSearchRequestBuilder prepareMultiSearch();