Add number of committed and number of search segments to the segments API response

This commit is contained in:
Shay Banon 2011-09-14 20:48:02 +03:00
parent e2b1cb1640
commit 3eaf73a380
2 changed files with 25 additions and 0 deletions

View File

@ -118,6 +118,9 @@ public class IndicesSegmentResponse extends BroadcastOperationResponse implement
}
builder.endObject();
builder.field(Fields.NUM_COMMITTED_SEGMENTS, shardSegments.numberOfCommitted());
builder.field(Fields.NUM_SEARCH_SEGMENTS, shardSegments.numberOfSearch());
builder.startObject(Fields.SEGMENTS);
for (Segment segment : shardSegments) {
builder.startObject(segment.name());
@ -156,6 +159,8 @@ public class IndicesSegmentResponse extends BroadcastOperationResponse implement
static final XContentBuilderString SEGMENTS = new XContentBuilderString("segments");
static final XContentBuilderString GENERATION = new XContentBuilderString("generation");
static final XContentBuilderString NUM_COMMITTED_SEGMENTS = new XContentBuilderString("num_committed_segments");
static final XContentBuilderString NUM_SEARCH_SEGMENTS = new XContentBuilderString("num_search_segments");
static final XContentBuilderString NUM_DOCS = new XContentBuilderString("num_docs");
static final XContentBuilderString DELETED_DOCS = new XContentBuilderString("deleted_docs");
static final XContentBuilderString SIZE = new XContentBuilderString("size");

View File

@ -68,6 +68,26 @@ public class ShardSegments extends BroadcastShardOperationResponse implements It
return segments;
}
public int numberOfCommitted() {
int count = 0;
for (Segment segment : segments) {
if (segment.committed()) {
count++;
}
}
return count;
}
public int numberOfSearch() {
int count = 0;
for (Segment segment : segments) {
if (segment.search()) {
count++;
}
}
return count;
}
public static ShardSegments readShardSegments(StreamInput in) throws IOException {
ShardSegments shard = new ShardSegments();
shard.readFrom(in);