use of org.elasticsearch.search.facet.FacetPhaseExecutionException in project geocluster-facet by zenobase.
the class GeoClusterFacetParser method parse.
@Override
public FacetExecutor parse(String facetName, XContentParser parser, SearchContext context) throws IOException {
String fieldName = null;
double factor = 0.1;
String currentName = parser.currentName();
XContentParser.Token token;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
currentName = parser.currentName();
} else if (token.isValue()) {
if ("field".equals(currentName)) {
fieldName = parser.text();
} else if ("factor".equals(currentName)) {
factor = parser.doubleValue();
}
}
}
if (factor < 0.0 || factor > 1.0) {
throw new FacetPhaseExecutionException(facetName, "value [" + factor + "] is not in range [0.0, 1.0]");
}
FieldMapper<?> fieldMapper = context.smartNameFieldMapper(fieldName);
if (fieldMapper == null) {
throw new FacetPhaseExecutionException(facetName, "failed to find mapping for [" + fieldName + "]");
}
IndexGeoPointFieldData indexFieldData = context.fieldData().getForField(fieldMapper);
return new GeoClusterFacetExecutor(indexFieldData, factor);
}
Aggregations