org.elasticsearch.client.ml.AbstractResultResponse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch-rest-high-level-client Show documentation
Show all versions of elasticsearch-rest-high-level-client Show documentation
Elasticsearch subproject :client:rest-high-level
/*
* 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.client.ml;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
* Abstract class that provides a list of results and their count.
*/
public abstract class AbstractResultResponse implements ToXContentObject {
public static final ParseField COUNT = new ParseField("count");
private final ParseField resultsField;
protected final List results;
protected final long count;
AbstractResultResponse(ParseField resultsField, List results, long count) {
this.resultsField = Objects.requireNonNull(resultsField, "[results_field] must not be null");
this.results = Collections.unmodifiableList(results);
this.count = count;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(COUNT.getPreferredName(), count);
builder.field(resultsField.getPreferredName(), results);
builder.endObject();
return builder;
}
public long count() {
return count;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy