diff --git a/src/main/java/org/elasticsearch/search/facet/statistical/StatisticalFacetParser.java b/src/main/java/org/elasticsearch/search/facet/statistical/StatisticalFacetParser.java index e4be4db33e2..1f553421d15 100644 --- a/src/main/java/org/elasticsearch/search/facet/statistical/StatisticalFacetParser.java +++ b/src/main/java/org/elasticsearch/search/facet/statistical/StatisticalFacetParser.java @@ -26,6 +26,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.fielddata.IndexNumericFieldData; import org.elasticsearch.index.mapper.FieldMapper; +import org.elasticsearch.index.mapper.core.NumberFieldMapper; import org.elasticsearch.search.facet.FacetExecutor; import org.elasticsearch.search.facet.FacetParser; import org.elasticsearch.search.facet.FacetPhaseExecutionException; @@ -104,6 +105,9 @@ public class StatisticalFacetParser extends AbstractComponent implements FacetPa if (fieldMapper == null) { throw new FacetPhaseExecutionException(facetName, "No mapping found for field [" + fieldsNames[i] + "]"); } + if (!(fieldMapper instanceof NumberFieldMapper)) { + throw new FacetPhaseExecutionException(facetName, "field [" + field + "] isn't a number field, but a " + fieldMapper.fieldDataType().getType()); + } indexFieldDatas[i] = context.fieldData().getForField(fieldMapper); } return new StatisticalFieldsFacetExecutor(indexFieldDatas, context); @@ -116,6 +120,9 @@ public class StatisticalFacetParser extends AbstractComponent implements FacetPa if (fieldMapper == null) { throw new FacetPhaseExecutionException(facetName, "No mapping found for field [" + field + "]"); } + if (!(fieldMapper instanceof NumberFieldMapper)) { + throw new FacetPhaseExecutionException(facetName, "field [" + field + "] isn't a number field, but a " + fieldMapper.fieldDataType().getType()); + } IndexNumericFieldData indexFieldData = context.fieldData().getForField(fieldMapper); return new StatisticalFacetExecutor(indexFieldData, context); } else { diff --git a/src/main/java/org/elasticsearch/search/facet/termsstats/TermsStatsFacetParser.java b/src/main/java/org/elasticsearch/search/facet/termsstats/TermsStatsFacetParser.java index 02fee504c4d..91cd44a87e6 100644 --- a/src/main/java/org/elasticsearch/search/facet/termsstats/TermsStatsFacetParser.java +++ b/src/main/java/org/elasticsearch/search/facet/termsstats/TermsStatsFacetParser.java @@ -26,6 +26,7 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.fielddata.IndexNumericFieldData; import org.elasticsearch.index.mapper.FieldMapper; +import org.elasticsearch.index.mapper.core.NumberFieldMapper; import org.elasticsearch.script.SearchScript; import org.elasticsearch.search.facet.FacetExecutor; import org.elasticsearch.search.facet.FacetParser; @@ -121,7 +122,11 @@ public class TermsStatsFacetParser extends AbstractComponent implements FacetPar IndexNumericFieldData valueIndexFieldData = null; SearchScript valueScript = null; if (valueField != null) { - valueIndexFieldData = context.fieldData().getForField(context.smartNameFieldMapper(valueField)); + FieldMapper fieldMapper = context.smartNameFieldMapper(valueField); + if (!(fieldMapper instanceof NumberFieldMapper)) { + throw new FacetPhaseExecutionException(facetName, "value_field [" + valueField + "] isn't a number field, but a " + fieldMapper.fieldDataType().getType()); + } + valueIndexFieldData = context.fieldData().getForField(fieldMapper); } else { valueScript = context.scriptService().search(context.lookup(), scriptLang, script, params); }