org.elasticsearch.client.RestHighLevelClient.search()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(315)

本文整理了Java中org.elasticsearch.client.RestHighLevelClient.search方法的一些代码示例,展示了RestHighLevelClient.search的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RestHighLevelClient.search方法的具体详情如下:
包路径:org.elasticsearch.client.RestHighLevelClient
类名称:RestHighLevelClient
方法名:search

RestHighLevelClient.search介绍

[英]Executes a search request using the Search API. See Search API on elastic.co
[中]使用搜索API执行搜索请求。见Search API on elastic.co

代码示例

代码示例来源:origin: spring-projects/spring-data-elasticsearch

private SearchResponse doSearch(SearchRequest searchRequest, SearchQuery searchQuery) {
  prepareSearch(searchRequest, searchQuery);
  try {
    return client.search(searchRequest);
  } catch (IOException e) {
    throw new ElasticsearchException("Error for search request with scroll: " + searchRequest.toString(), e);
  }
}

代码示例来源:origin: spring-projects/spring-data-elasticsearch

private long doCount(SearchRequest countRequest, QueryBuilder elasticsearchQuery) {
  SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
  if (elasticsearchQuery != null) {
    sourceBuilder.query(elasticsearchQuery);
  }
  countRequest.source(sourceBuilder);
  try {
    return client.search(countRequest).getHits().getTotalHits();
  } catch (IOException e) {
    throw new ElasticsearchException("Error while searching for request: " + countRequest.toString(), e);
  }
}

代码示例来源:origin: spring-projects/spring-data-elasticsearch

private SearchResponse doScroll(SearchRequest request, SearchQuery searchQuery) {
  Assert.notNull(searchQuery.getIndices(), "No index defined for Query");
  Assert.notNull(searchQuery.getTypes(), "No type define for Query");
  Assert.notNull(searchQuery.getPageable(), "Query.pageable is required for scan & scroll");
  if (searchQuery.getFilter() != null) {
    request.source().postFilter(searchQuery.getFilter());
  }
  request.source().version(true);
  try {
    return client.search(request);
  } catch (IOException e) {
    throw new ElasticsearchException("Error for search request with scroll: " + request.toString(), e);
  }
}

代码示例来源:origin: spring-projects/spring-data-elasticsearch

public SearchResponse suggest(SuggestBuilder suggestion, String... indices) {
  SearchRequest searchRequest = new SearchRequest(indices);
  SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
  sourceBuilder.suggest(suggestion);
  searchRequest.source(sourceBuilder);
  try {
    return client.search(searchRequest);
  } catch (IOException e) {
    throw new ElasticsearchException("Could not execute search request : " + searchRequest.toString(), e);
  }
}

代码示例来源:origin: Netflix/conductor

searchRequest.source(searchSourceBuilder);
SearchResponse response = elasticSearchClient.search(searchRequest);

代码示例来源:origin: spring-projects/spring-data-elasticsearch

private long doCount(SearchRequest searchRequest, QueryBuilder elasticsearchQuery, QueryBuilder elasticsearchFilter) {
  if (elasticsearchQuery != null) {
    searchRequest.source().query(elasticsearchQuery);
  } else {
    searchRequest.source().query(QueryBuilders.matchAllQuery());
  }
  if (elasticsearchFilter != null) {
    searchRequest.source().postFilter(elasticsearchFilter);
  }
  SearchResponse response;
  try {
    response = client.search(searchRequest);
  } catch (IOException e) {
    throw new ElasticsearchException("Error for search request: " + searchRequest.toString(), e);
  }
  return response.getHits().getTotalHits();
}

代码示例来源:origin: spring-projects/spring-data-elasticsearch

@Override
public <T> List<String> queryForIds(SearchQuery query) {
  SearchRequest request = prepareSearch(query, Optional.ofNullable(query.getQuery()));
  request.source().query(query.getQuery());
  if (query.getFilter() != null) {
    request.source().postFilter(query.getFilter());
  }
  SearchResponse response;
  try {
    response = client.search(request);
  } catch (IOException e) {
    throw new ElasticsearchException("Error for search request: " + request.toString(), e);
  }
  return extractIds(response);
}

代码示例来源:origin: spring-projects/spring-data-elasticsearch

@Override
public <T> Page<T> queryForPage(StringQuery query, Class<T> clazz, SearchResultMapper mapper) {
  SearchRequest request = prepareSearch(query, clazz);
  request.source().query((wrapperQuery(query.getSource())));
  SearchResponse response;
  try {
    response = client.search(request);
  } catch (IOException e) {
    throw new ElasticsearchException("Error for search request: " + request.toString(), e);
  }
  return mapper.mapResults(response, clazz, query.getPageable());
}

代码示例来源:origin: Netflix/conductor

searchRequest.source(searchSourceBuilder);
SearchResponse response = elasticSearchClient.search(searchRequest);

代码示例来源:origin: spring-projects/spring-data-elasticsearch

private SearchResponse doScroll(SearchRequest request, CriteriaQuery criteriaQuery) {
  Assert.notNull(criteriaQuery.getIndices(), "No index defined for Query");
  Assert.notNull(criteriaQuery.getTypes(), "No type define for Query");
  Assert.notNull(criteriaQuery.getPageable(), "Query.pageable is required for scan & scroll");
  QueryBuilder elasticsearchQuery = new CriteriaQueryProcessor().createQueryFromCriteria(criteriaQuery.getCriteria());
  QueryBuilder elasticsearchFilter = new CriteriaFilterProcessor()
      .createFilterFromCriteria(criteriaQuery.getCriteria());
  if (elasticsearchQuery != null) {
    request.source().query(elasticsearchQuery);
  } else {
    request.source().query(QueryBuilders.matchAllQuery());
  }
  if (elasticsearchFilter != null) {
    request.source().postFilter(elasticsearchFilter);
  }
  request.source().version(true);
  try {
    return client.search(request);
  } catch (IOException e) {
    throw new ElasticsearchException("Error for search request with scroll: " + request.toString(), e);
  }
}

代码示例来源:origin: Netflix/conductor

@Override
public List<EventExecution> getEventExecutions(String event) {
  try {
    Expression expression = Expression.fromString("event='" + event + "'");
    QueryBuilder queryBuilder = expression.getFilterBuilder();
    BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(queryBuilder);
    QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery("*");
    BoolQueryBuilder query = QueryBuilders.boolQuery().must(stringQuery).must(filterQuery);
    // Create the searchObjectIdsViaExpression source
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    searchSourceBuilder.query(query);
    searchSourceBuilder.sort(new FieldSortBuilder("created").order(SortOrder.ASC));
    // Generate the actual request to send to ES.
    SearchRequest searchRequest = new SearchRequest(logIndexPrefix + "*");
    searchRequest.types(EVENT_DOC_TYPE);
    searchRequest.source(searchSourceBuilder);
    SearchResponse response = elasticSearchClient.search(searchRequest);
    return mapEventExecutionsResponse(response);
  } catch (Exception e) {
    logger.error("Failed to get executions for event: {}", event, e);
    throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, e.getMessage(), e);
  }
}

代码示例来源:origin: Netflix/conductor

@Override
public List<Message> getMessages(String queue) {
  try {
    Expression expression = Expression.fromString("queue='" + queue + "'");
    QueryBuilder queryBuilder = expression.getFilterBuilder();
    BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(queryBuilder);
    QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery("*");
    BoolQueryBuilder query = QueryBuilders.boolQuery().must(stringQuery).must(filterQuery);
    // Create the searchObjectIdsViaExpression source
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    searchSourceBuilder.query(query);
    searchSourceBuilder.sort(new FieldSortBuilder("created").order(SortOrder.ASC));
    // Generate the actual request to send to ES.
    SearchRequest searchRequest = new SearchRequest(logIndexPrefix + "*");
    searchRequest.types(MSG_DOC_TYPE);
    searchRequest.source(searchSourceBuilder);
    SearchResponse response = elasticSearchClient.search(searchRequest);
    return mapGetMessagesResponse(response);
  } catch (Exception e) {
    logger.error("Failed to get messages for queue: {}", queue, e);
    throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, e.getMessage(), e);
  }
}

代码示例来源:origin: Netflix/conductor

searchRequest.source(searchSourceBuilder);
return elasticSearchClient.search(searchRequest);

代码示例来源:origin: spring-projects/spring-data-elasticsearch

@Override
public <T> Page<T> queryForPage(CriteriaQuery criteriaQuery, Class<T> clazz) {
  QueryBuilder elasticsearchQuery = new CriteriaQueryProcessor().createQueryFromCriteria(criteriaQuery.getCriteria());
  QueryBuilder elasticsearchFilter = new CriteriaFilterProcessor()
      .createFilterFromCriteria(criteriaQuery.getCriteria());
  SearchRequest request = prepareSearch(criteriaQuery, clazz);
  if (elasticsearchQuery != null) {
    request.source().query(elasticsearchQuery);
  } else {
    request.source().query(QueryBuilders.matchAllQuery());
  }
  if (criteriaQuery.getMinScore() > 0) {
    request.source().minScore(criteriaQuery.getMinScore());
  }
  if (elasticsearchFilter != null)
    request.source().postFilter(elasticsearchFilter);
  if (logger.isDebugEnabled()) {
    logger.debug("doSearch query:\n" + request.toString());
  }
  SearchResponse response;
  try {
    response = client.search(request);
  } catch (IOException e) {
    throw new ElasticsearchException("Error for search request: " + request.toString(), e);
  }
  return resultsMapper.mapResults(response, clazz, criteriaQuery.getPageable());
}

代码示例来源:origin: apache/metron

public ElasticsearchRequestSubmitter setup(SearchResponse response) throws IOException {
 // mocks
 RestHighLevelClient highLevelClient = mock(RestHighLevelClient.class);
 ElasticsearchClient client = new ElasticsearchClient(mock(RestClient.class), highLevelClient);
 // the client should return the given search response
 when(highLevelClient.search(any())).thenReturn(response);
 return new ElasticsearchRequestSubmitter(client);
}

代码示例来源:origin: apache/metron

esResponse = client.getHighLevelClient().search(request);
LOG.debug("Got Elasticsearch response with {} hit(s); response={}",
    esResponse.getHits().getTotalHits(), esResponse.toString());

代码示例来源:origin: tomoya92/pybbs

builder.from((pageNo - 1) * pageSize).size(pageSize);
request.source(builder);
SearchResponse response = client.search(request, RequestOptions.DEFAULT);

代码示例来源:origin: apache/metron

request.indices(index);
org.elasticsearch.action.search.SearchResponse esResponse = transportClient.search(request);
List<SearchResult> allResults = getSearchResults(esResponse);
long total = esResponse.getHits().getTotalHits();
  int from = i * pageSize;
  builder.from(from);
  esResponse = transportClient.search(request);
  allResults.addAll(getSearchResults(esResponse));

代码示例来源:origin: dadoonet/fscrawler

searchRequest.indicesOptions(LENIENT_EXPAND_OPEN);
SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
ESSearchResponse esSearchResponse = new ESSearchResponse();
if (response.getHits() != null) {

代码示例来源:origin: dadoonet/fscrawler

searchRequest.indicesOptions(IndicesOptions.lenientExpandOpen());
SearchResponse response = client.search(searchRequest);
ESSearchResponse esSearchResponse = new ESSearchResponse();
if (response.getHits() != null) {

相关文章