-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add parsing for single bucket aggregations #24564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cbuescher
merged 3 commits into
elastic:feature/client_aggs_parsing
from
cbuescher:addParsing-SingleBucket-v2
May 11, 2017
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...main/java/org/elasticsearch/search/aggregations/bucket/ParsedSingleBucketAggregation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.elasticsearch.search.aggregations.bucket; | ||
|
|
||
| import org.elasticsearch.common.xcontent.XContentBuilder; | ||
| import org.elasticsearch.common.xcontent.XContentParser; | ||
| import org.elasticsearch.common.xcontent.XContentParserUtils; | ||
| import org.elasticsearch.search.aggregations.Aggregation; | ||
| import org.elasticsearch.search.aggregations.Aggregations; | ||
| import org.elasticsearch.search.aggregations.ParsedAggregation; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken; | ||
|
|
||
| /** | ||
| * A base class for all the single bucket aggregations. | ||
| */ | ||
| public abstract class ParsedSingleBucketAggregation extends ParsedAggregation implements SingleBucketAggregation { | ||
|
|
||
| private long docCount; | ||
| protected Aggregations aggregations = new Aggregations(Collections.emptyList()); | ||
|
|
||
| @Override | ||
| public long getDocCount() { | ||
| return docCount; | ||
| } | ||
|
|
||
| protected void setDocCount(long docCount) { | ||
| this.docCount = docCount; | ||
| } | ||
|
|
||
| @Override | ||
| public Aggregations getAggregations() { | ||
| return aggregations; | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { | ||
| builder.field(CommonFields.DOC_COUNT.getPreferredName(), docCount); | ||
| aggregations.toXContentInternal(builder, params); | ||
| return builder; | ||
| } | ||
|
|
||
| protected static <T extends ParsedSingleBucketAggregation> T parseXContent(final XContentParser parser, T aggregation, String name) | ||
| throws IOException { | ||
| aggregation.setName(name); | ||
| XContentParser.Token token = parser.currentToken(); | ||
| String currentFieldName = parser.currentName(); | ||
| if (token == XContentParser.Token.FIELD_NAME) { | ||
| token = parser.nextToken(); | ||
| } | ||
| ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser::getTokenLocation); | ||
|
|
||
| List<Aggregation> aggregations = new ArrayList<>(); | ||
| while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { | ||
| if (token == XContentParser.Token.FIELD_NAME) { | ||
| currentFieldName = parser.currentName(); | ||
| } else if (token.isValue()) { | ||
| if (CommonFields.DOC_COUNT.getPreferredName().equals(currentFieldName)) { | ||
| aggregation.setDocCount(parser.longValue()); | ||
| } | ||
| } else if (token == XContentParser.Token.START_OBJECT) { | ||
| if (CommonFields.META.getPreferredName().equals(currentFieldName)) { | ||
| aggregation.metadata = parser.map(); | ||
| } else { | ||
| aggregations.add(XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class)); | ||
| } | ||
| } | ||
| } | ||
| aggregation.aggregations = new Aggregations(aggregations); | ||
| return aggregation; | ||
| } | ||
| } | ||
36 changes: 36 additions & 0 deletions
36
core/src/main/java/org/elasticsearch/search/aggregations/bucket/children/ParsedChildren.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.elasticsearch.search.aggregations.bucket.children; | ||
|
|
||
| import org.elasticsearch.common.xcontent.XContentParser; | ||
| import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class ParsedChildren extends ParsedSingleBucketAggregation implements Children { | ||
|
|
||
| @Override | ||
| public String getType() { | ||
| return ChildrenAggregationBuilder.NAME; | ||
| } | ||
|
|
||
| public static ParsedChildren fromXContent(XContentParser parser, final String name) throws IOException { | ||
| return parseXContent(parser, new ParsedChildren(), name); | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
core/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/ParsedFilter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.elasticsearch.search.aggregations.bucket.filter; | ||
|
|
||
| import org.elasticsearch.common.xcontent.XContentParser; | ||
| import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class ParsedFilter extends ParsedSingleBucketAggregation implements Filter { | ||
|
|
||
| @Override | ||
| public String getType() { | ||
| return FilterAggregationBuilder.NAME; | ||
| } | ||
|
|
||
| public static ParsedFilter fromXContent(XContentParser parser, final String name) throws IOException { | ||
| return parseXContent(parser, new ParsedFilter(), name); | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/ParsedGlobal.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.elasticsearch.search.aggregations.bucket.global; | ||
|
|
||
| import org.elasticsearch.common.xcontent.XContentParser; | ||
| import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class ParsedGlobal extends ParsedSingleBucketAggregation implements Global { | ||
|
|
||
| @Override | ||
| public String getType() { | ||
| return GlobalAggregationBuilder.NAME; | ||
| } | ||
|
|
||
| public static ParsedGlobal fromXContent(XContentParser parser, final String name) throws IOException { | ||
| return parseXContent(parser, new ParsedGlobal(), name); | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
core/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/ParsedMissing.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.elasticsearch.search.aggregations.bucket.missing; | ||
|
|
||
| import org.elasticsearch.common.xcontent.XContentParser; | ||
| import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class ParsedMissing extends ParsedSingleBucketAggregation implements Missing { | ||
|
|
||
| @Override | ||
| public String getType() { | ||
| return MissingAggregationBuilder.NAME; | ||
| } | ||
|
|
||
| public static ParsedMissing fromXContent(XContentParser parser, final String name) throws IOException { | ||
| return parseXContent(parser, new ParsedMissing(), name); | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/ParsedNested.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.elasticsearch.search.aggregations.bucket.nested; | ||
|
|
||
| import org.elasticsearch.common.xcontent.XContentParser; | ||
| import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class ParsedNested extends ParsedSingleBucketAggregation implements Nested { | ||
|
|
||
| @Override | ||
| public String getType() { | ||
| return NestedAggregationBuilder.NAME; | ||
| } | ||
|
|
||
| public static ParsedNested fromXContent(XContentParser parser, final String name) throws IOException { | ||
| return parseXContent(parser, new ParsedNested(), name); | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
...rc/main/java/org/elasticsearch/search/aggregations/bucket/nested/ParsedReverseNested.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.elasticsearch.search.aggregations.bucket.nested; | ||
|
|
||
| import org.elasticsearch.common.xcontent.XContentParser; | ||
| import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class ParsedReverseNested extends ParsedSingleBucketAggregation implements Nested { | ||
|
|
||
| @Override | ||
| public String getType() { | ||
| return ReverseNestedAggregationBuilder.NAME; | ||
| } | ||
|
|
||
| public static ParsedReverseNested fromXContent(XContentParser parser, final String name) throws IOException { | ||
| return parseXContent(parser, new ParsedReverseNested(), name); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/ParsedSampler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.elasticsearch.search.aggregations.bucket.sampler; | ||
|
|
||
| import org.elasticsearch.common.xcontent.XContentParser; | ||
| import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class ParsedSampler extends ParsedSingleBucketAggregation implements Sampler { | ||
|
|
||
| @Override | ||
| public String getType() { | ||
| return InternalSampler.NAME; | ||
| } | ||
|
|
||
| public static ParsedSampler fromXContent(XContentParser parser, final String name) throws IOException { | ||
| return parseXContent(parser, new ParsedSampler(), name); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now I see what you meant yesterday saying that we have to parse meta here