private Map<String, String> getFieldTypes(DocumentMapper documentMapper) { Map<String, String> fieldNameToDataType = new HashMap<>(); for (FieldMapper<?> fieldMapper : documentMapper.mappers()) { String type; if (fieldMapper instanceof AbstractFieldMapper) { try { type = (String) abstractFieldMapperContentTypeMethod.invoke(fieldMapper); } catch (Exception ex) { throw new RuntimeException("Could not find content type", ex); } } else { type = fieldMapper.fieldDataType().getType(); } fieldNameToDataType.put(fieldMapper.name(), type); } return fieldNameToDataType; } }
private LongArrayIndexFieldData getKeyFieldData(final String facetName, final String fieldName, final SearchContext context) { if(fieldName != null) { final FieldMapper<?> mapper = context.smartNameFieldMapper(fieldName); if(mapper == null) { throw new FacetPhaseExecutionException(facetName, "no mapping found for " + fieldName); } if(!"long".equals(mapper.fieldDataType().getType())) { throw new FacetPhaseExecutionException(facetName, "key field " + fieldName + " is not of type long"); } return context.fieldData().getForField(mapper); } else throw new FacetPhaseExecutionException(facetName, "[key_field] is required to be set for date facet"); }
keyFieldName); if ((keyFieldMapper != null) && !(keyFieldMapper.fieldDataType().getType().equals(LatestFacetExecutor.keyDataType.getType()))) { throw new FacetPhaseExecutionException(facetName, "key field must be of type long but is " + keyFieldMapper.fieldDataType().getType()); && !(tsFieldMapper.fieldDataType().getType().equals(LatestFacetExecutor.tsDataType.getType()))) { throw new FacetPhaseExecutionException(facetName, "ts field must be of type long but is " + tsFieldMapper.fieldDataType().getType()); if (valueFieldMapper.fieldDataType().getType().equals("int") || valueFieldMapper.fieldDataType().getType().equals("long")) { IndexNumericFieldData valueFieldData = context.fieldData().getForField(valueFieldMapper); IndexNumericFieldData keyFieldData = context.fieldData().getForField(keyFieldMapper);
if (!"string".equals(mapper.fieldDataType().getType())) { logger.warn("No String mapping found for Field : {} ", field); throw new FacetPhaseExecutionException(facetName, "No String mapping found for field [" + field + "] not found");
FieldDataType dataType = fieldMapper.fieldDataType(); if (dataType != null) { mapper.put("fieldDataType", dataType.getType());
if (keyMapper == null) { throw new FacetPhaseExecutionException(facetName, "(key) field [" + keyField + "] not found"); } else if (!keyMapper.fieldDataType().getType().equals("long")) { throw new FacetPhaseExecutionException(facetName, "(key) field [" + keyField + "] is not of type date"); if (distinctFieldMapper.fieldDataType().getType().equals("string")) { PagedBytesIndexFieldData distinctFieldData = context.fieldData().getForField(distinctFieldMapper); PackedArrayIndexFieldData keyIndexFieldData = context.fieldData().getForField(keyMapper); return new StringDistinctDateHistogramFacetExecutor(keyIndexFieldData, distinctFieldData, dateTime, interval, comparatorType, context.cacheRecycler()); } else if (distinctFieldMapper.fieldDataType().getType().equals("long")) { IndexNumericFieldData distinctFieldData = context.fieldData().getForField(distinctFieldMapper); IndexNumericFieldData keyIndexFieldData = context.fieldData().getForField(keyMapper);
throw new FacetPhaseExecutionException(facetName, "(key) field [" + keyField + "] not found"); if (mapper.fieldDataType() != FieldDataType.DefaultTypes.LONG) { throw new FacetPhaseExecutionException(facetName, "(key) field [" + keyField + "] is not of type date");
if (smartMappers.mapper().fieldDataType() != FieldDataType.DefaultTypes.STRING) { throw new ElasticSearchIllegalArgumentException( "Field [" + fieldName + "] is not of string type, can't run hashed string facet collector on it"); this.fieldDataType = smartMappers.mapper().fieldDataType();
public FacetedDateHistogramCollector(String facetName, String keyFieldName, TimeZoneRounding tzRounding, FacetProcessor internalProcessor, byte[] internalFacetConfig, SearchContext context) throws IOException { super(facetName); this.fieldDataCache = context.fieldDataCache(); this.keyFieldName = keyFieldName; MapperService.SmartNameFieldMappers smartMappers = context .smartFieldMappers(keyFieldName); if (smartMappers == null || !smartMappers.hasMapper()) { throw new FacetPhaseExecutionException(facetName, "No mapping found for field [" + keyFieldName + "]"); } // add type filter if there is exact doc mapper associated with it if (smartMappers.explicitTypeInNameWithDocMapper()) { setFilter(context.filterCache().cache( smartMappers.docMapper().typeFilter())); } keyIndexFieldName = smartMappers.mapper().names().indexName(); keyFieldDataType = smartMappers.mapper().fieldDataType(); InternalCollectorFactory colFactory= new InternalCollectorFactory(facetName, internalProcessor, internalFacetConfig, context); logger.debug("Facet {}: Test running internal facet processor ", facetName); this.internalExampleCollector = colFactory.createInternalCollector(); this.histoProc = new DateHistogramProc(facetName,tzRounding,colFactory); }