}
if (valueField == null && script == null) {
throw new FacetPhaseExecutionException(facetName, "either [value_field] or [script] are required to be set for terms stats facet");
}
FieldMapper keyFieldMapper = context.mapperService().smartNameFieldMapper(keyField);
if (keyFieldMapper != null) {
if (keyFieldMapper.fieldDataType() == FieldDataType.DefaultTypes.LONG) {
return new TermsStatsLongFacetCollector(facetName, keyField, valueField, size, comparatorType, context, scriptLang, script, params);
} else if (keyFieldMapper.fieldDataType() == FieldDataType.DefaultTypes.INT) {
return new TermsStatsLongFacetCollector(facetName, keyField, valueField, size, comparatorType, context, scriptLang, script, params);
} else if (keyFieldMapper.fieldDataType() == FieldDataType.DefaultTypes.SHORT) {
return new TermsStatsLongFacetCollector(facetName, keyField, valueField, size, comparatorType, context, scriptLang, script, params);
} else if (keyFieldMapper.fieldDataType() == FieldDataType.DefaultTypes.BYTE) {
return new TermsStatsLongFacetCollector(facetName, keyField, valueField, size, comparatorType, context, scriptLang, script, params);
} else if (keyFieldMapper.fieldDataType() == FieldDataType.DefaultTypes.DOUBLE) {
return new TermsStatsDoubleFacetCollector(facetName, keyField, valueField, size, comparatorType, context, scriptLang, script, params);
} else if (keyFieldMapper.fieldDataType() == FieldDataType.DefaultTypes.FLOAT) {
return new TermsStatsDoubleFacetCollector(facetName, keyField, valueField, size, comparatorType, context, scriptLang, script, params);
}
}
return new TermsStatsStringFacetCollector(facetName, keyField, valueField, size, comparatorType, context, scriptLang, script, params);