コード例 #1
0
  @Override
  public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    if (scrollId != null) {
      builder.field(Fields._SCROLL_ID, scrollId);
    }
    builder.field(Fields.TOOK, tookInMillis);
    builder.field(Fields.TIMED_OUT, isTimedOut());
    if (isTerminatedEarly() != null) {
      builder.field(Fields.TERMINATED_EARLY, isTerminatedEarly());
    }
    builder.startObject(Fields._SHARDS);
    builder.field(Fields.TOTAL, getTotalShards());
    builder.field(Fields.SUCCESSFUL, getSuccessfulShards());
    builder.field(Fields.FAILED, getFailedShards());

    if (shardFailures.length > 0) {
      builder.startArray(Fields.FAILURES);
      for (ShardSearchFailure shardFailure : shardFailures) {
        builder.startObject();
        if (shardFailure.shard() != null) {
          builder.field(Fields.INDEX, shardFailure.shard().index());
          builder.field(Fields.SHARD, shardFailure.shard().shardId());
        }
        builder.field(Fields.STATUS, shardFailure.status().getStatus());
        builder.field(Fields.REASON, shardFailure.reason());
        builder.endObject();
      }
      builder.endArray();
    }

    builder.endObject();
    internalResponse.toXContent(builder, params);
    return builder;
  }
コード例 #2
0
 private Response wrap(SearchResponse response) {
   List<SearchFailure> failures;
   if (response.getShardFailures() == null) {
     failures = emptyList();
   } else {
     failures = new ArrayList<>(response.getShardFailures().length);
     for (ShardSearchFailure failure : response.getShardFailures()) {
       String nodeId = failure.shard() == null ? null : failure.shard().nodeId();
       failures.add(
           new SearchFailure(failure.getCause(), failure.index(), failure.shardId(), nodeId));
     }
   }
   List<Hit> hits;
   if (response.getHits().getHits() == null || response.getHits().getHits().length == 0) {
     hits = emptyList();
   } else {
     hits = new ArrayList<>(response.getHits().getHits().length);
     for (SearchHit hit : response.getHits().getHits()) {
       hits.add(new ClientHit(hit));
     }
     hits = unmodifiableList(hits);
   }
   return new Response(
       response.isTimedOut(),
       failures,
       response.getHits().getTotalHits(),
       hits,
       response.getScrollId());
 }