Better error description if field(s) (statistical facet) and value_field (term_stats facet) are not a numeric field
This commit is contained in:
parent
6a3c53ef44
commit
637eeacb20
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue