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

x33g5p2x  于2022-01-18 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(166)

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

Client.prepareSearchScroll介绍

[英]A search scroll request to continue searching a previous scrollable search request.
[中]搜索滚动请求以继续搜索以前的可滚动搜索请求。

代码示例

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

public SearchScrollRequestBuilder getScrollBuilder(String scrollId){
  return esProvider.getClient().prepareSearchScroll( scrollId );
}

代码示例来源:origin: NLPchina/elasticsearch-sql

private List<SearchHit> scrollTillLimit(TableInJoinRequestBuilder tableInJoinRequest, Integer hintLimit) {
  SearchResponse scrollResp = scrollOneTimeWithMax(client,tableInJoinRequest);
  updateMetaSearchResults(scrollResp);
  List<SearchHit> hitsWithScan = new ArrayList<>();
  int curentNumOfResults = 0;
  SearchHit[] hits = scrollResp.getHits().getHits();
  if (hintLimit == null) hintLimit = MAX_RESULTS_FOR_FIRST_TABLE;
  while (hits.length != 0 && curentNumOfResults < hintLimit) {
    curentNumOfResults += hits.length;
    Collections.addAll(hitsWithScan, hits);
    if (curentNumOfResults >= MAX_RESULTS_FOR_FIRST_TABLE) {
      //todo: log or exception?
      System.out.println("too many results for first table, stoping at:" + curentNumOfResults);
      break;
    }
    scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(600000)).execute().actionGet();
    hits = scrollResp.getHits().getHits();
  }
  return hitsWithScan;
}

代码示例来源:origin: NLPchina/elasticsearch-sql

break;
scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(600000)).execute().actionGet();
hits = scrollResp.getHits().getHits();
  break;
scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(600000)).execute().actionGet();
hits = scrollResp.getHits().getHits();

代码示例来源:origin: loklak/loklak_server

/**
 * Delete documents using a query. Check what would be deleted first with a normal search query!
 * Elasticsearch once provided a native prepareDeleteByQuery method, but this was removed
 * in later versions. Instead, there is a plugin which iterates over search results,
 * see https://www.elastic.co/guide/en/elasticsearch/plugins/current/plugins-delete-by-query.html
 * We simulate the same behaviour here without the need of that plugin.
 *
 * @param q
 * @return delete document count
 */
public int deleteByQuery(String indexName, final QueryBuilder q) {
  Map<String, String> ids = new TreeMap<>();
  // FIXME: deprecated, "will be removed in 3.0, you should do a regular scroll instead, ordered by `_doc`"
  @SuppressWarnings("deprecation")
  SearchResponse response = elasticsearchClient.prepareSearch(indexName).setSearchType(SearchType.SCAN)
    .setScroll(new TimeValue(60000)).setQuery(q).setSize(100).execute().actionGet();
  while (true) {
    // accumulate the ids here, don't delete them right now to prevent an interference of the delete with the
    // scroll
    for (SearchHit hit : response.getHits().getHits()) {
      ids.put(hit.getId(), hit.getType());
    }
    response = elasticsearchClient.prepareSearchScroll(response.getScrollId()).setScroll(new TimeValue(600000))
      .execute().actionGet();
    // termination
    if (response.getHits().getHits().length == 0)
      break;
  }
  return deleteBulk(indexName, ids);
}

代码示例来源:origin: NLPchina/elasticsearch-sql

break;
  responseForSecondTable = client.prepareSearchScroll(responseForSecondTable.getScrollId()).setScroll(new TimeValue(600000)).execute().actionGet();
  secondQueryHits = responseForSecondTable.getHits().getHits();
scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(600000)).execute().actionGet();
hits = scrollResp.getHits().getHits();

代码示例来源:origin: NLPchina/elasticsearch-sql

searchResponse = client.prepareSearchScroll(searchResponse.getScrollId()).setScroll(new TimeValue(600000)).execute().actionGet();
  } else break;
} else {

代码示例来源:origin: NLPchina/elasticsearch-sql

firstTableResponse = client.prepareSearchScroll(firstTableResponse.getScrollId()).setScroll(new TimeValue(600000)).get();
else finishedWithFirstTable = true;

代码示例来源:origin: SonarSource/sonarqube

/**
 * Get all the indexed documents (no paginated results). Results are not sorted.
 */
public List<SearchHit> getDocuments(IndexType indexType) {
 SearchRequestBuilder req = SHARED_NODE.client().prepareSearch(indexType.getIndex()).setTypes(indexType.getType()).setQuery(matchAllQuery());
 EsUtils.optimizeScrollRequest(req);
 req.setScroll(new TimeValue(60000))
  .setSize(100);
 SearchResponse response = req.get();
 List<SearchHit> result = newArrayList();
 while (true) {
  Iterables.addAll(result, response.getHits());
  response = SHARED_NODE.client().prepareSearchScroll(response.getScrollId()).setScroll(new TimeValue(600000)).execute().actionGet();
  // Break condition: No hits are returned
  if (response.getHits().getHits().length == 0) {
   break;
  }
 }
 return result;
}

代码示例来源:origin: yacy/yacy_grid_mcp

ids.put(hit.getId(), hit.getType());
response = elasticsearchClient.prepareSearchScroll(response.getScrollId()).setScroll(new TimeValue(600000))
  .execute().actionGet();

代码示例来源:origin: org.apache.metamodel/MetaModel-elasticsearch-native

@Override
  protected SearchResponse scrollSearchResponse(final String scrollId) {
    return _client.prepareSearchScroll(scrollId).setScroll(ElasticSearchDataContext.TIMEOUT_SCROLL)
        .execute().actionGet();
  }
}

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

@Override
  protected SearchResponse scrollSearchResponse(final String scrollId) {
    return _client.prepareSearchScroll(scrollId).setScroll(ElasticSearchDataContext.TIMEOUT_SCROLL)
        .execute().actionGet();
  }
}

代码示例来源:origin: org.vertexium/vertexium-elasticsearch2

@Override
protected SearchResponse getNextSearchResponse(String scrollId) {
  try {
    return client.prepareSearchScroll(scrollId)
        .setScroll(scrollKeepAlive)
        .execute().actionGet();
  } catch (Exception ex) {
    throw new VertexiumException("Failed to request more items from scroll " + scrollId, ex);
  }
}

代码示例来源:origin: org.apache.james/apache-james-backends-es

@Override
public SearchResponse next() {
  SearchResponse result = searchResponseFuture.actionGet();
  searchResponseFuture =  client.prepareSearchScroll(result.getScrollId())
    .setScroll(TIMEOUT)
    .execute();
  return result;
}

代码示例来源:origin: org.vertexium/vertexium-elasticsearch5

@Override
protected SearchResponse getNextSearchResponse(String scrollId) {
  try {
    return client.prepareSearchScroll(scrollId)
        .setScroll(scrollKeepAlive)
        .execute().actionGet();
  } catch (Exception ex) {
    throw new VertexiumException("Failed to request more items from scroll " + scrollId, ex);
  }
}

代码示例来源:origin: org.vertexium/vertexium-elasticsearch-singledocument

@Override
protected SearchResponse getNextSearchResponse(String scrollId) {
  try {
    return client.prepareSearchScroll(scrollId)
        .setScroll(scrollKeepAlive)
        .execute().actionGet();
  } catch (Exception ex) {
    throw new VertexiumException("Failed to request more items from scroll " + scrollId, ex);
  }
}

代码示例来源:origin: karussell/elasticsearch-reindex

@Override public int doScoll() {
  rsp = client.prepareSearchScroll(scrollId()).setScroll(TimeValue.timeValueMinutes(keepTimeInMinutes)).
      execute().actionGet();
  return rsp.getHits().hits().length;
}

代码示例来源:origin: searchisko/elasticsearch-river-jira

@Override
public SearchResponse executeESScrollSearchNextRequest(SearchResponse scrollResp) {
  return client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(ES_SCROLL_KEEPALIVE)).execute()
      .actionGet();
}

代码示例来源:origin: codelibs/elasticsearch-reindexing

@Override
public void onResponse(final BulkResponse bulkResponse) {
  if (bulkResponse.hasFailures()) {
    throw new ReindexingException(bulkResponse
        .buildFailureMessage());
  }
  client.prepareSearchScroll(scrollId).setScroll(scroll)
      .execute(ReindexingListener.this);
}

代码示例来源:origin: Aconex/scrutineer

void consumeBatches(ObjectOutputStream objectOutputStream, SearchResponse initialSearchResponse) throws IOException {
  SearchResponse batchSearchResponse = initialSearchResponse;
  while (writeSearchResponseToOutputStream(objectOutputStream, batchSearchResponse)) {
    String scrollId = batchSearchResponse.getScrollId();
    batchSearchResponse = client.prepareSearchScroll(scrollId).setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES)).execute().actionGet();
  }
}

代码示例来源:origin: ujmp/universal-java-matrix-package

public KeyIterator(ElasticsearchIndex index) {
  this.index = index;
  MatchAllQueryBuilder query = QueryBuilders.matchAllQuery();
  scrollResp = index.getClient().prepareSearch(index.getIndex()).setTypes(index.getType())
      .addFields(new String[] {}).setSearchType(SearchType.SCAN)
      .setScroll(new TimeValue(ElasticsearchIndex.SCROLLTIMEOUT)).setQuery(query)
      .setSize(ElasticsearchIndex.SCROLLSIZE).execute().actionGet();
  scrollResp = index.getClient().prepareSearchScroll(scrollResp.getScrollId())
      .setScroll(new TimeValue(ElasticsearchIndex.SCROLLTIMEOUT)).execute().actionGet();
  iterator = scrollResp.getHits().iterator();
}

相关文章