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; } }
@Override public Builder fieldDataSettings(Settings fieldDataSettings) { Settings settings = Settings.builder().put(childJoinFieldType.fieldDataType().getSettings()).put(fieldDataSettings).build(); childJoinFieldType.setFieldDataType(new FieldDataType(childJoinFieldType.fieldDataType().getType(), settings)); return this; }
protected void setupFieldType(BuilderContext context) { fieldType.setNames(buildNames(context)); if (fieldType.indexAnalyzer() == null && fieldType.tokenized() == false && fieldType.indexOptions() != IndexOptions.NONE) { fieldType.setIndexAnalyzer(Lucene.KEYWORD_ANALYZER); fieldType.setSearchAnalyzer(Lucene.KEYWORD_ANALYZER); } if (fieldDataSettings != null) { Settings settings = Settings.builder().put(fieldType.fieldDataType().getSettings()).put(fieldDataSettings).build(); fieldType.setFieldDataType(new FieldDataType(fieldType.fieldDataType().getType(), settings)); } boolean defaultDocValues = false; // pre 2.0 if (context.indexCreatedVersion().onOrAfter(Version.V_2_0_0_beta1)) { defaultDocValues = fieldType.tokenized() == false && fieldType.indexOptions() != IndexOptions.NONE; } // backcompat for "fielddata: format: docvalues" for now... boolean fieldDataDocValues = fieldType.fieldDataType() != null && FieldDataType.DOC_VALUES_FORMAT_VALUE.equals(fieldType.fieldDataType().getFormat(context.indexSettings())); if (fieldDataDocValues && docValuesSet && fieldType.hasDocValues() == false) { // this forces the doc_values setting to be written, so fielddata does not mask the original setting defaultDocValues = true; } defaultFieldType.setHasDocValues(defaultDocValues); if (docValuesSet == false) { fieldType.setHasDocValues(defaultDocValues || fieldDataDocValues); } } }
IndexFieldData.Builder builder = null; Settings indexSettings = indexSettings(); String format = type.getFormat(indexSettings); if (format != null && FieldDataType.DOC_VALUES_FORMAT_VALUE.equals(format) && !docValues) { logger.warn("field [" + fieldNames.fullName() + "] has no doc values, will use default field data format"); builder = buildersByTypeAndFormat.get(Tuple.tuple(type.getType(), format)); if (builder == null) { logger.warn("failed to find format [" + format + "] for field [" + fieldNames.fullName() + "], will use default"); builder = docValuesBuildersByType.get(type.getType()); builder = buildersByType.get(type.getType()); throw new IllegalArgumentException("failed to find field data builder for field " + fieldNames.fullName() + ", and type " + type.getType()); String cacheType = type.getSettings().get("cache", indexSettings.get(FIELDDATA_CACHE_KEY, FIELDDATA_CACHE_VALUE_NODE)); if (FIELDDATA_CACHE_VALUE_NODE.equals(cacheType)) { cache = indicesFieldDataCache.buildIndexFieldDataCache(listener, index, fieldNames, type);
@Override public FieldDataType defaultFieldDataType() { return new FieldDataType("string"); }
private boolean joinFieldHasCustomFieldDataSettings() { return childJoinFieldType != null && childJoinFieldType.fieldDataType() != null && childJoinFieldType.fieldDataType().equals(Defaults.JOIN_FIELD_TYPE.fieldDataType()) == false; }
continue; if (fieldDataType.getLoading() != Loading.EAGER_GLOBAL_ORDINALS) { continue;
public DateFieldType() { super(NumericType.LONG); setFieldDataType(new FieldDataType("long")); }
protected boolean hasCustomFieldDataSettings() { return fieldType().fieldDataType() != null && fieldType().fieldDataType().equals(defaultFieldType.fieldDataType()) == false; }
continue; if (fieldDataType.getLoading() == Loading.LAZY) { continue;
private final Query toFieldDataTermsQuery(MappedFieldType fieldType, IndexFieldData fieldData, byte[] encodedTerms, long cacheKey) { Query query = null; if (fieldType instanceof NumberFieldMapper.NumberFieldType) { query = FieldDataTermsQuery.newLongs(encodedTerms, (IndexNumericFieldData) fieldData, cacheKey); } else if (fieldType instanceof StringFieldMapper.StringFieldType) { query = FieldDataTermsQuery.newBytes(encodedTerms, fieldData, cacheKey); } else { throw new ElasticsearchParseException("[fielddata_terms] query does not support field data type " + fieldType.fieldDataType().getType()); } return query; }
public TypeFieldType() { setFieldDataType(new FieldDataType("string")); }
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"); }
public VersionFieldType() { setFieldDataType(new FieldDataType("long")); }
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);
public UidFieldType() { setFieldDataType(new FieldDataType("string")); }
mapper.put("fieldDataType", dataType.getType());
public RoutingFieldType() { setFieldDataType(new FieldDataType("string")); }
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");
public AllFieldType() { setFieldDataType(new FieldDataType("string")); }