Skip to content

Commit

Permalink
Move aggs CommonFields and TYPED_KEYS_DELIMITER from InternalAggregat…
Browse files Browse the repository at this point in the history
…ion to Aggregation (#23987)

These will be shared between internal objects and objects exposed through high level REST client, so they should be moved from internal classes.
  • Loading branch information
javanna committed Apr 10, 2017
1 parent 0736f9b commit 95edcc8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@
*/
package org.elasticsearch.search.aggregations;

import org.elasticsearch.common.ParseField;

import java.util.Map;

/**
* An aggregation
*/
public interface Aggregation {

/**
* Delimiter used when prefixing aggregation names with their type
* using the typed_keys parameter
*/
String TYPED_KEYS_DELIMITER = "#";

/**
* @return The name of this aggregation.
*/
Expand All @@ -34,4 +42,22 @@ public interface Aggregation {
* Get the optional byte array metadata that was set on the aggregation
*/
Map<String, Object> getMetaData();

/**
* Common xcontent fields that are shared among addAggregation
*/
final class CommonFields extends ParseField.CommonFields {
public static final ParseField META = new ParseField("meta");
public static final ParseField BUCKETS = new ParseField("buckets");
public static final ParseField VALUE = new ParseField("value");
public static final ParseField VALUES = new ParseField("values");
public static final ParseField VALUE_AS_STRING = new ParseField("value_as_string");
public static final ParseField DOC_COUNT = new ParseField("doc_count");
public static final ParseField KEY = new ParseField("key");
public static final ParseField KEY_AS_STRING = new ParseField("key_as_string");
public static final ParseField FROM = new ParseField("from");
public static final ParseField FROM_AS_STRING = new ParseField("from_as_string");
public static final ParseField TO = new ParseField("to");
public static final ParseField TO_AS_STRING = new ParseField("to_as_string");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.elasticsearch.search.aggregations;

import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.NamedWriteable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand All @@ -39,9 +38,6 @@
*/
public abstract class InternalAggregation implements Aggregation, ToXContent, NamedWriteable {

/** Delimiter used when prefixing aggregation names with their type using the typed_keys parameter **/
public static final String TYPED_KEYS_DELIMITER = "#";

public static class ReduceContext {

private final BigArrays bigArrays;
Expand Down Expand Up @@ -199,22 +195,4 @@ public final XContentBuilder toXContent(XContentBuilder builder, Params params)
}

public abstract XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException;

/**
* Common xcontent fields that are shared among addAggregation
*/
public static final class CommonFields extends ParseField.CommonFields {
public static final ParseField META = new ParseField("meta");
public static final ParseField BUCKETS = new ParseField("buckets");
public static final ParseField VALUE = new ParseField("value");
public static final ParseField VALUES = new ParseField("values");
public static final ParseField VALUE_AS_STRING = new ParseField("value_as_string");
public static final ParseField DOC_COUNT = new ParseField("doc_count");
public static final ParseField KEY = new ParseField("key");
public static final ParseField KEY_AS_STRING = new ParseField("key_as_string");
public static final ParseField FROM = new ParseField("from");
public static final ParseField FROM_AS_STRING = new ParseField("from_as_string");
public static final ParseField TO = new ParseField("to");
public static final ParseField TO_AS_STRING = new ParseField("to_as_string");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
Expand Down Expand Up @@ -59,7 +60,7 @@ public InternalAggregation doReduce(List<InternalAggregation> aggregations, Redu

@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
builder.field(InternalAggregation.CommonFields.DOC_COUNT.getPreferredName(), 0);
builder.field(Aggregation.CommonFields.DOC_COUNT.getPreferredName(), 0);
return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.rest.action.search.RestSearchAction;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry;
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry.Option;
import org.elasticsearch.search.suggest.completion.CompletionSuggestion;
Expand Down Expand Up @@ -382,7 +382,7 @@ public void innerWriteTo(StreamOutput out) throws IOException {
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
if (params.paramAsBoolean(RestSearchAction.TYPED_KEYS_PARAM, false)) {
// Concatenates the type and the name of the suggestion (ex: completion#foo)
builder.startArray(String.join(InternalAggregation.TYPED_KEYS_DELIMITER, getType(), getName()));
builder.startArray(String.join(Aggregation.TYPED_KEYS_DELIMITER, getType(), getName()));
} else {
builder.startArray(getName());
}
Expand All @@ -398,7 +398,7 @@ public static Suggestion<? extends Entry<? extends Option>> fromXContent(XConten
ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation);
String typeAndName = parser.currentName();
// we need to extract the type prefix from the name and throw error if it is not present
int delimiterPos = typeAndName.indexOf(InternalAggregation.TYPED_KEYS_DELIMITER);
int delimiterPos = typeAndName.indexOf(Aggregation.TYPED_KEYS_DELIMITER);
String type;
String name;
if (delimiterPos > 0) {
Expand Down

0 comments on commit 95edcc8

Please sign in to comment.