getProperty method in the aggregations framework now throws a specific exception

This commit is contained in:
Colin Goodheart-Smithe 2015-02-16 10:51:31 +00:00
parent 3ab3ffa989
commit f20dae85a9
2 changed files with 37 additions and 4 deletions

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;
import org.elasticsearch.search.aggregations.reducers.Reducer;
@ -58,18 +57,19 @@ public abstract class InternalMultiBucketAggregation extends InternalAggregation
String aggName = path.get(0);
if (aggName.equals("_count")) {
if (path.size() > 1) {
throw new ElasticsearchIllegalArgumentException("_count must be the last element in the path");
throw new InvalidAggregationPathException("_count must be the last element in the path");
}
return getDocCount();
} else if (aggName.equals("_key")) {
if (path.size() > 1) {
throw new ElasticsearchIllegalArgumentException("_key must be the last element in the path");
throw new InvalidAggregationPathException("_key must be the last element in the path");
}
return getKey();
}
InternalAggregation aggregation = aggregations.get(aggName);
if (aggregation == null) {
throw new ElasticsearchIllegalArgumentException("Cannot find an aggregation named [" + aggName + "] in [" + containingAggName + "]");
throw new InvalidAggregationPathException("Cannot find an aggregation named [" + aggName + "] in [" + containingAggName
+ "]");
}
return aggregation.getProperty(path.subList(1, path.size()));
}

View File

@ -0,0 +1,33 @@
/*
* 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;
import org.elasticsearch.ElasticsearchException;
public class InvalidAggregationPathException extends ElasticsearchException {
public InvalidAggregationPathException(String msg) {
super(msg);
}
public InvalidAggregationPathException(String msg, Throwable cause) {
super(msg, cause);
}
}