}
}
}
if (entries.isEmpty()) {
throw new FacetPhaseExecutionException(facetName, "no ranges defined for range facet");
}
RangeFacet.Entry[] rangeEntries = entries.toArray(new RangeFacet.Entry[entries.size()]);
// fix the range entries if needed
if (keyField != null) {
FieldMapper mapper = context.mapperService().smartNameFieldMapper(keyField);
if (mapper == null) {
throw new FacetPhaseExecutionException(facetName, "No mapping found for key_field [" + keyField + "]");
}
for (RangeFacet.Entry entry : rangeEntries) {
if (entry.fromAsString != null) {
entry.from = ((Number) mapper.valueFromString(entry.fromAsString)).doubleValue();
}
if (entry.toAsString != null) {
entry.to = ((Number) mapper.valueFromString(entry.toAsString)).doubleValue();
}
}
}
if (keyScript != null && valueScript != null) {
return new ScriptRangeFacetCollector(facetName, scriptLang, keyScript, valueScript, params, rangeEntries, context);
}
if (keyField == null) {
throw new FacetPhaseExecutionException(facetName, "key field is required to be set for range facet, either using [field] or using [key_field]");
}
if (valueField == null || keyField.equals(valueField)) {
return new RangeFacetCollector(facetName, keyField, rangeEntries, context);
} else {