org.elasticsearch.search.builder.SearchSourceBuilder.slice()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(173)

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

SearchSourceBuilder.slice介绍

[英]Gets the slice used to filter the search hits, the top hits and the aggregations.
[中]获取用于筛选搜索命中率、最热门命中率和聚合的片段。

代码示例

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

public SearchRequestBuilder slice(SliceBuilder builder) {
  sourceBuilder().slice(builder);
  return this;
}

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

@Override
public ActionRequestValidationException validate() {
  ActionRequestValidationException e = searchRequest.validate();
  if (searchRequest.source().from() != -1) {
    e = addValidationError("from is not supported in this context", e);
  }
  if (searchRequest.source().storedFields() != null) {
    e = addValidationError("stored_fields is not supported in this context", e);
  }
  if (maxRetries < 0) {
    e = addValidationError("retries cannot be negative", e);
  }
  if (false == (size == -1 || size > 0)) {
    e = addValidationError(
        "size should be greater than 0 if the request is limited to some number of documents or -1 if it isn't but it was ["
            + size + "]",
        e);
  }
  if (searchRequest.source().slice() != null && slices != DEFAULT_SLICES) {
    e = addValidationError("can't specify both manual and automatic slicing at the same time", e);
  }
  return e;
}

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

public SearchRequestBuilder slice(SliceBuilder builder) {
  sourceBuilder().slice(builder);
  return this;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

public SearchRequestBuilder slice(SliceBuilder builder) {
  sourceBuilder().slice(builder);
  return this;
}

代码示例来源:origin: apache/servicemix-bundles

public SearchRequestBuilder slice(SliceBuilder builder) {
  sourceBuilder().slice(builder);
  return this;
}

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

if (source.slice() != null) {
  if (context.scrollContext() == null) {
    throw new SearchContextException(context, "`slice` cannot be used outside of a scroll context");
  context.sliceBuilder(source.slice());

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

@Override
public Task createTask(long id, String type, String action, TaskId parentTaskId) {
  if (slices > 1) {
    return new ParentBulkByScrollTask(id, type, action, getDescription(), parentTaskId, slices);
  }
  /* Extract the slice from the search request so it'll be available in the status. This is potentially useful for users that manually
   * slice their search requests so they can keep track of it and **absolutely** useful for automatically sliced reindex requests so
   * they can properly track the responses. */
  Integer sliceId = searchRequest.source().slice() == null ? null : searchRequest.source().slice().getId();
  return new WorkingBulkByScrollTask(id, type, action, getDescription(), parentTaskId, sliceId, requestsPerSecond);
}

代码示例来源:origin: org.elasticsearch.plugin/reindex-client

/**
   * Slice a search request into {@code times} separate search requests slicing on {@code field}. Note that the slices are *shallow*
   * copies of this request so don't change them.
   */
  static SearchRequest[] sliceIntoSubRequests(SearchRequest request, String field, int times) {
    SearchRequest[] slices = new SearchRequest[times];
    for (int slice = 0; slice < times; slice++) {
      SliceBuilder sliceBuilder = new SliceBuilder(field, slice, times);
      SearchSourceBuilder slicedSource;
      if (request.source() == null) {
        slicedSource = new SearchSourceBuilder().slice(sliceBuilder);
      } else {
        if (request.source().slice() != null) {
          throw new IllegalStateException("Can't slice a request that already has a slice configuration");
        }
        slicedSource = request.source().copyWithNewSlice(sliceBuilder);
      }
      SearchRequest searchRequest = new SearchRequest(request);
      searchRequest.source(slicedSource);
      slices[slice] = searchRequest;
    }
    return slices;
  }
}

代码示例来源:origin: org.elasticsearch.plugin/reindex-client

private static <Request extends AbstractBulkByScrollRequest<Request>> void sliceConditionally(
    Request request,
    BulkByScrollTask task,
    Action<Request, BulkByScrollResponse, ?> action,
    ActionListener<BulkByScrollResponse> listener,
    Client client,
    DiscoveryNode node,
    Runnable workerAction,
    int slices) {
  if (slices > 1) {
    task.setWorkerCount(slices);
    sendSubRequests(client, action, node.getId(), task, request, listener);
  } else {
    SliceBuilder sliceBuilder = request.getSearchRequest().source().slice();
    Integer sliceId = sliceBuilder == null
      ? null
      : sliceBuilder.getId();
    task.setWorker(request.getRequestsPerSecond(), sliceId);
    workerAction.run();
  }
}

代码示例来源:origin: org.elasticsearch.plugin/reindex-client

private static <Request extends AbstractBulkByScrollRequest<Request>> void sendSubRequests(
    Client client,
    Action<Request, BulkByScrollResponse, ?> action,
    String localNodeId,
    BulkByScrollTask task,
    Request request,
    ActionListener<BulkByScrollResponse> listener) {
  LeaderBulkByScrollTaskState worker = task.getLeaderState();
  int totalSlices = worker.getSlices();
  TaskId parentTaskId = new TaskId(localNodeId, task.getId());
  for (final SearchRequest slice : sliceIntoSubRequests(request.getSearchRequest(), IdFieldMapper.NAME, totalSlices)) {
    // TODO move the request to the correct node. maybe here or somehow do it as part of startup for reindex in general....
    Request requestForSlice = request.forSlice(parentTaskId, slice, totalSlices);
    ActionListener<BulkByScrollResponse> sliceListener = ActionListener.wrap(
        r -> worker.onSliceResponse(listener, slice.source().slice().getId(), r),
        e -> worker.onSliceFailure(listener, slice.source().slice().getId(), e));
    client.execute(action, requestForSlice, sliceListener);
  }
}

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

@Override
public ActionRequestValidationException validate() {
  ActionRequestValidationException e = searchRequest.validate();
  if (searchRequest.source().from() != -1) {
    e = addValidationError("from is not supported in this context", e);
  }
  if (searchRequest.source().storedFields() != null) {
    e = addValidationError("stored_fields is not supported in this context", e);
  }
  if (maxRetries < 0) {
    e = addValidationError("retries cannnot be negative", e);
  }
  if (false == (size == -1 || size > 0)) {
    e = addValidationError(
        "size should be greater than 0 if the request is limited to some number of documents or -1 if it isn't but it was ["
            + size + "]",
        e);
  }
  if (searchRequest.source().slice() != null && slices != 1) {
    e = addValidationError("can't specify both slice and workers", e);
  }
  return e;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

@Override
public ActionRequestValidationException validate() {
  ActionRequestValidationException e = searchRequest.validate();
  if (searchRequest.source().from() != -1) {
    e = addValidationError("from is not supported in this context", e);
  }
  if (searchRequest.source().storedFields() != null) {
    e = addValidationError("stored_fields is not supported in this context", e);
  }
  if (maxRetries < 0) {
    e = addValidationError("retries cannot be negative", e);
  }
  if (false == (size == -1 || size > 0)) {
    e = addValidationError(
        "size should be greater than 0 if the request is limited to some number of documents or -1 if it isn't but it was ["
            + size + "]",
        e);
  }
  if (searchRequest.source().slice() != null && slices != DEFAULT_SLICES) {
    e = addValidationError("can't specify both manual and automatic slicing at the same time", e);
  }
  return e;
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public ActionRequestValidationException validate() {
  ActionRequestValidationException e = searchRequest.validate();
  if (searchRequest.source().from() != -1) {
    e = addValidationError("from is not supported in this context", e);
  }
  if (searchRequest.source().storedFields() != null) {
    e = addValidationError("stored_fields is not supported in this context", e);
  }
  if (maxRetries < 0) {
    e = addValidationError("retries cannnot be negative", e);
  }
  if (false == (size == -1 || size > 0)) {
    e = addValidationError(
        "size should be greater than 0 if the request is limited to some number of documents or -1 if it isn't but it was ["
            + size + "]",
        e);
  }
  if (searchRequest.source().slice() != null && slices != DEFAULT_SLICES) {
    e = addValidationError("can't specify both manual and automatic slicing at the same time", e);
  }
  return e;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

if (source.slice() != null) {
  if (context.scrollContext() == null) {
    throw new SearchContextException(context, "`slice` cannot be used outside of a scroll context");
  context.sliceBuilder(source.slice());

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

int id = randomInt(max-1);
if (field == null) {
  builder.slice(new SliceBuilder(id, max));
} else {
  builder.slice(new SliceBuilder(field, id, max));

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

if (source.slice() != null) {
  if (context.scrollContext() == null) {
    throw new SearchContextException(context, "`slice` cannot be used outside of a scroll context");
  context.sliceBuilder(source.slice());

相关文章

微信公众号

最新文章

更多

SearchSourceBuilder类方法