All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.elasticsearch.action.admin.indices.stats.FieldUsageStatsResponse Maven / Gradle / Ivy

There is a newer version: 8.13.4
Show newest version
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0 and the Server Side Public License, v 1; you may not use this file except
 * in compliance with, at your election, the Elastic License 2.0 or the Server
 * Side Public License, v 1.
 */

package org.elasticsearch.action.admin.indices.stats;

import org.elasticsearch.action.support.DefaultShardOperationFailedException;
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.List;
import java.util.Map;

public class FieldUsageStatsResponse extends BroadcastResponse {
    private final Map> stats;

    FieldUsageStatsResponse(
        int totalShards,
        int successfulShards,
        int failedShards,
        List shardFailures,
        Map> stats
    ) {
        super(totalShards, successfulShards, failedShards, shardFailures);
        this.stats = stats;
    }

    FieldUsageStatsResponse(StreamInput in) throws IOException {
        super(in);
        stats = in.readMap(StreamInput::readString, i -> i.readList(FieldUsageShardResponse::new));
    }

    @Override
    public void writeTo(StreamOutput out) throws IOException {
        super.writeTo(out);
        out.writeMap(stats, StreamOutput::writeString, StreamOutput::writeList);
    }

    public Map> getStats() {
        return stats;
    }

    @Override
    protected void addCustomXContentFields(XContentBuilder builder, Params params) throws IOException {
        final List>> sortedEntries = stats.entrySet()
            .stream()
            .sorted(Map.Entry.comparingByKey())
            .toList();
        for (Map.Entry> entry : sortedEntries) {
            builder.startObject(entry.getKey());
            builder.startArray("shards");
            for (FieldUsageShardResponse resp : entry.getValue()) {
                resp.toXContent(builder, params);
            }
            builder.endArray();
            builder.endObject();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy