|
@@ -8,11 +8,13 @@
|
|
|
|
|
|
package org.elasticsearch.index.mapper;
|
|
|
|
|
|
+import org.elasticsearch.TransportVersions;
|
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
|
import org.elasticsearch.common.io.stream.Writeable;
|
|
|
import org.elasticsearch.common.unit.ByteSizeValue;
|
|
|
import org.elasticsearch.core.Nullable;
|
|
|
+import org.elasticsearch.features.NodeFeature;
|
|
|
import org.elasticsearch.xcontent.ToXContentFragment;
|
|
|
import org.elasticsearch.xcontent.XContentBuilder;
|
|
|
|
|
@@ -25,15 +27,22 @@ import java.util.Objects;
|
|
|
*/
|
|
|
public class NodeMappingStats implements Writeable, ToXContentFragment {
|
|
|
|
|
|
+ public static final NodeFeature SEGMENT_LEVEL_FIELDS_STATS = new NodeFeature("mapper.segment_level_fields_stats");
|
|
|
+
|
|
|
private static final class Fields {
|
|
|
static final String MAPPINGS = "mappings";
|
|
|
static final String TOTAL_COUNT = "total_count";
|
|
|
static final String TOTAL_ESTIMATED_OVERHEAD = "total_estimated_overhead";
|
|
|
static final String TOTAL_ESTIMATED_OVERHEAD_IN_BYTES = "total_estimated_overhead_in_bytes";
|
|
|
+ static final String TOTAL_SEGMENTS = "total_segments";
|
|
|
+ static final String TOTAL_SEGMENT_FIELDS = "total_segment_fields";
|
|
|
+ static final String AVERAGE_FIELDS_PER_SEGMENT = "average_fields_per_segment";
|
|
|
}
|
|
|
|
|
|
private long totalCount;
|
|
|
private long totalEstimatedOverhead;
|
|
|
+ private long totalSegments;
|
|
|
+ private long totalSegmentFields;
|
|
|
|
|
|
public NodeMappingStats() {
|
|
|
|
|
@@ -42,17 +51,25 @@ public class NodeMappingStats implements Writeable, ToXContentFragment {
|
|
|
public NodeMappingStats(StreamInput in) throws IOException {
|
|
|
totalCount = in.readVLong();
|
|
|
totalEstimatedOverhead = in.readVLong();
|
|
|
+ if (in.getTransportVersion().onOrAfter(TransportVersions.SEGMENT_LEVEL_FIELDS_STATS)) {
|
|
|
+ totalSegments = in.readVLong();
|
|
|
+ totalSegmentFields = in.readVLong();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public NodeMappingStats(long totalCount, long totalEstimatedOverhead) {
|
|
|
+ public NodeMappingStats(long totalCount, long totalEstimatedOverhead, long totalSegments, long totalSegmentFields) {
|
|
|
this.totalCount = totalCount;
|
|
|
this.totalEstimatedOverhead = totalEstimatedOverhead;
|
|
|
+ this.totalSegments = totalSegments;
|
|
|
+ this.totalSegmentFields = totalSegmentFields;
|
|
|
}
|
|
|
|
|
|
public void add(@Nullable NodeMappingStats other) {
|
|
|
if (other == null) return;
|
|
|
this.totalCount += other.totalCount;
|
|
|
this.totalEstimatedOverhead += other.totalEstimatedOverhead;
|
|
|
+ this.totalSegments += other.totalSegments;
|
|
|
+ this.totalSegmentFields += other.totalSegmentFields;
|
|
|
}
|
|
|
|
|
|
public long getTotalCount() {
|
|
@@ -63,10 +80,22 @@ public class NodeMappingStats implements Writeable, ToXContentFragment {
|
|
|
return ByteSizeValue.ofBytes(totalEstimatedOverhead);
|
|
|
}
|
|
|
|
|
|
+ public long getTotalSegments() {
|
|
|
+ return totalSegments;
|
|
|
+ }
|
|
|
+
|
|
|
+ public long getTotalSegmentFields() {
|
|
|
+ return totalSegmentFields;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void writeTo(StreamOutput out) throws IOException {
|
|
|
out.writeVLong(totalCount);
|
|
|
out.writeVLong(totalEstimatedOverhead);
|
|
|
+ if (out.getTransportVersion().onOrAfter(TransportVersions.SEGMENT_LEVEL_FIELDS_STATS)) {
|
|
|
+ out.writeVLong(totalSegments);
|
|
|
+ out.writeVLong(totalSegmentFields);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -74,6 +103,9 @@ public class NodeMappingStats implements Writeable, ToXContentFragment {
|
|
|
builder.startObject(Fields.MAPPINGS);
|
|
|
builder.field(Fields.TOTAL_COUNT, getTotalCount());
|
|
|
builder.humanReadableField(Fields.TOTAL_ESTIMATED_OVERHEAD_IN_BYTES, Fields.TOTAL_ESTIMATED_OVERHEAD, getTotalEstimatedOverhead());
|
|
|
+ builder.field(Fields.TOTAL_SEGMENTS, totalSegments);
|
|
|
+ builder.field(Fields.TOTAL_SEGMENT_FIELDS, totalSegmentFields);
|
|
|
+ builder.field(Fields.AVERAGE_FIELDS_PER_SEGMENT, totalSegments == 0 ? 0 : totalSegmentFields / totalSegments);
|
|
|
builder.endObject();
|
|
|
return builder;
|
|
|
}
|
|
@@ -83,11 +115,14 @@ public class NodeMappingStats implements Writeable, ToXContentFragment {
|
|
|
if (this == o) return true;
|
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
|
NodeMappingStats that = (NodeMappingStats) o;
|
|
|
- return totalCount == that.totalCount && totalEstimatedOverhead == that.totalEstimatedOverhead;
|
|
|
+ return totalCount == that.totalCount
|
|
|
+ && totalEstimatedOverhead == that.totalEstimatedOverhead
|
|
|
+ && totalSegments == that.totalSegments
|
|
|
+ && totalSegmentFields == that.totalSegmentFields;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int hashCode() {
|
|
|
- return Objects.hash(totalCount, totalEstimatedOverhead);
|
|
|
+ return Objects.hash(totalCount, totalEstimatedOverhead, totalSegments, totalSegmentFields);
|
|
|
}
|
|
|
}
|