예제 #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 void checkExceptions(String script) {
   try {
     SearchResponse sr =
         client()
             .prepareSearch("test")
             .setQuery(QueryBuilders.matchAllQuery())
             .addScriptField("tvtest", script)
             .execute()
             .actionGet();
     assertThat(sr.getHits().hits().length, equalTo(0));
     ShardSearchFailure[] shardFails = sr.getShardFailures();
     for (ShardSearchFailure fail : shardFails) {
       assertThat(
           fail.reason()
               .indexOf(
                   "Cannot iterate twice! If you want to iterate more that once, add _CACHE explicitly."),
           Matchers.greaterThan(-1));
     }
   } catch (SearchPhaseExecutionException ex) {
     assertThat(
         "got " + ex.getDetailedMessage(),
         ex.getDetailedMessage()
             .indexOf(
                 "Cannot iterate twice! If you want to iterate more that once, add _CACHE explicitly."),
         Matchers.greaterThan(-1));
   }
 }