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

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

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

Client.prepareClearScroll介绍

[英]Clears the search contexts associated with specified scroll ids.
[中]清除与指定滚动ID关联的搜索上下文。

代码示例

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

public List<String> findAllViewUuids() {
  SearchRequestBuilder esSearch = esClient.prepareSearch(ViewIndexDefinition.INDEX_TYPE_VIEW)
   .addSort("_doc", SortOrder.ASC)
   .setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES))
   .setFetchSource(false)
   .setSize(100)
   .setQuery(matchAllQuery());

  SearchResponse response = esSearch.get();
  List<String> result = newArrayList();
  while (true) {
   List<SearchHit> hits = newArrayList(response.getHits());
   for (SearchHit hit : hits) {
    result.add(hit.getId());
   }
   String scrollId = response.getScrollId();
   response = esClient.prepareSearchScroll(scrollId)
    .setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES))
    .get();
   // Break condition: No hits are returned
   if (response.getHits().getHits().length == 0) {
    esClient.nativeClient().prepareClearScroll().addScrollId(scrollId).get();
    break;
   }
  }
  return result;
 }
}

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

client.nativeClient().prepareClearScroll().addScrollId(scrollId).get();
break;

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

private void closeScroll(String scrollId) {
  try {
    client.prepareClearScroll()
        .addScrollId(scrollId)
        .execute().actionGet();
  } catch (Exception ex) {
    throw new VertexiumException("Could not close iterator " + scrollId, ex);
  }
}

代码示例来源:origin: harbby/presto-connectors

@Override
  public void close()
  {
    client.prepareClearScroll().addScrollId(firstScrollResp.getScrollId()).execute().actionGet();
  }
};

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

private void closeScroll(String scrollId) {
  try {
    client.prepareClearScroll()
        .addScrollId(scrollId)
        .execute().actionGet();
  } catch (Exception ex) {
    throw new VertexiumException("Could not close iterator " + scrollId, ex);
  }
}

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

private void closeScroll(String scrollId) {
  try {
    client.prepareClearScroll()
        .addScrollId(scrollId)
        .execute().actionGet();
  } catch (Exception ex) {
    throw new VertexiumException("Could not close iterator " + scrollId, ex);
  }
}

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

public void interrupt() {
  interrupted.set(true);
  if (scrollId != null) {
    client.prepareClearScroll().addScrollId(scrollId)
        .execute(new ActionListener<ClearScrollResponse>() {
          @Override
          public void onResponse(ClearScrollResponse response) {
            // nothing
          }
          @Override
          public void onFailure(Throwable e) {
            if (logger.isDebugEnabled()) {
              logger.debug(
                  "Failed to stop reindexing for "
                      + toIndex + ".", e);
            }
          }
        });
  }
}

代码示例来源:origin: visallo/vertexium

private void closeScroll(String scrollId) {
  try {
    client.prepareClearScroll()
        .addScrollId(scrollId)
        .execute().actionGet();
  } catch (Exception ex) {
    throw new VertexiumException("Could not close iterator " + scrollId, ex);
  }
}

代码示例来源:origin: harbby/presto-connectors

@Override
  public void close()
      throws IOException
  {
    client.prepareClearScroll().addScrollId(firstScrollResp.getScrollId()).execute().actionGet();
  }
};

代码示例来源:origin: com.strapdata.elasticsearch.test/framework

/**
 * Clears the given scroll Ids
 */
public void clearScroll(String... scrollIds) {
  ClearScrollResponse clearResponse = client().prepareClearScroll()
    .setScrollIds(Arrays.asList(scrollIds)).get();
  assertThat(clearResponse.isSucceeded(), equalTo(true));
}

代码示例来源:origin: harbby/presto-connectors

@Override
  public void close()
      throws IOException
  {
    client.prepareClearScroll().addScrollId(firstScrollResp.getScrollId()).execute().actionGet();
  }
};

代码示例来源:origin: Anchormen/sql4es

public void close() throws SQLException {
  if(this.esResponse != null && this.esResponse.getScrollId() != null){
    client.prepareClearScroll().addScrollId(this.esResponse.getScrollId()).execute();
  }
  if(this.result != null) result.close();
}

代码示例来源:origin: com.scireum/sirius-search

private void clearScroll(SearchResponse searchResponse) {
  try {
    indexAccess.getClient()
          .prepareClearScroll()
          .addScrollId(searchResponse.getScrollId())
          .execute()
          .actionGet();
  } catch (Exception e) {
    Exceptions.handle(IndexAccess.LOG, e);
  }
}

代码示例来源:origin: pinterest/soundwave

protected <E extends EsDocument> ScrollableResponse<List<E>> scrollNext(
  String scrollId, ThrowingFunction<String, E> createFunc)
  throws Exception {
 SearchScrollRequestBuilder
   builder =
   esClient.prepareSearchScroll(scrollId)
     .setScroll(TimeValue.timeValueMillis(SCROLLDEFAULTTIMEOUT));
 SearchResponse response = builder.execute().actionGet();
 ArrayList<E> list = new ArrayList<>();
 ScrollableResponse<List<E>> ret = new ScrollableResponse<>();
 ret.setValue(list);
 ret.setContinousToken(response.getScrollId());
 if (response.getHits().totalHits() == 0) {
  //Clear the scroll as early as possible to save resource
  ClearScrollRequestBuilder
    clearRequestBuilder =
    esClient.prepareClearScroll().addScrollId(scrollId);
  clearRequestBuilder.execute();
  ret.setScrollToEnd(true);
 } else {
  for (int i = 0; i < response.getHits().getHits().length; i++) {
   String str = response.getHits().getAt(i).getSourceAsString();
   E element = createFunc.apply(str);
   element.setId(response.getHits().getAt(i).getId());
   list.add(element);
  }
 }
 return ret;
}

代码示例来源:origin: Anchormen/sql4es

public void buildRequest(String sql, QueryBody query, String... indices) throws SQLException {
  if(this.esResponse != null && this.esResponse.getScrollId() != null){
    client.prepareClearScroll().addScrollId(this.esResponse.getScrollId()).execute();

代码示例来源:origin: org.sonarsource.sonarqube/sonar-server

public List<String> findAllViewUuids() {
  SearchRequestBuilder esSearch = esClient.prepareSearch(ViewIndexDefinition.INDEX_TYPE_VIEW)
   .addSort("_doc", SortOrder.ASC)
   .setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES))
   .setFetchSource(false)
   .setSize(100)
   .setQuery(matchAllQuery());

  SearchResponse response = esSearch.get();
  List<String> result = newArrayList();
  while (true) {
   List<SearchHit> hits = newArrayList(response.getHits());
   for (SearchHit hit : hits) {
    result.add(hit.getId());
   }
   String scrollId = response.getScrollId();
   response = esClient.prepareSearchScroll(scrollId)
    .setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES))
    .get();
   // Break condition: No hits are returned
   if (response.getHits().getHits().length == 0) {
    esClient.nativeClient().prepareClearScroll().addScrollId(scrollId).get();
    break;
   }
  }
  return result;
 }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-server

client.nativeClient().prepareClearScroll().addScrollId(scrollId).get();
break;

相关文章