@Override public void checkCompatibility( MappedFieldType fieldType, List<String> conflicts, boolean strict) { super.checkCompatibility(fieldType, conflicts, strict); GeoPointFieldType other = (GeoPointFieldType) fieldType; if (isLatLonEnabled() != other.isLatLonEnabled()) { conflicts.add("mapper [" + names().fullName() + "] has different lat_lon"); } if (isGeohashEnabled() != other.isGeohashEnabled()) { conflicts.add("mapper [" + names().fullName() + "] has different geohash"); } if (geohashPrecision() != other.geohashPrecision()) { conflicts.add("mapper [" + names().fullName() + "] has different geohash_precision"); } if (isGeohashPrefixEnabled() != other.isGeohashPrefixEnabled()) { conflicts.add("mapper [" + names().fullName() + "] has different geohash_prefix"); } if (isLatLonEnabled() && other.isLatLonEnabled() && latFieldType().numericPrecisionStep() != other.latFieldType().numericPrecisionStep()) { conflicts.add("mapper [" + names().fullName() + "] has different precision_step"); } }
@Override public GeoPointFieldMapper build(BuilderContext context) { ContentPath.Type origPathType = context.path().pathType(); context.path().pathType(pathType); DoubleFieldMapper latMapper = null; DoubleFieldMapper lonMapper = null; GeoPointFieldType geoPointFieldType = (GeoPointFieldType) fieldType; context.path().add(name); if (enableLatLon) { NumberFieldMapper.Builder<?, ?> latMapperBuilder = doubleField(Names.LAT).includeInAll(false); NumberFieldMapper.Builder<?, ?> lonMapperBuilder = doubleField(Names.LON).includeInAll(false); if (precisionStep != null) { latMapperBuilder.precisionStep(precisionStep); lonMapperBuilder.precisionStep(precisionStep); } latMapper = (DoubleFieldMapper) latMapperBuilder .includeInAll(false) .store(fieldType.stored()) .docValues(false) .build(context); lonMapper = (DoubleFieldMapper) lonMapperBuilder .includeInAll(false) .store(fieldType.stored()) .docValues(false) .build(context); geoPointFieldType.setLatLonEnabled(latMapper.fieldType(), lonMapper.fieldType()); } StringFieldMapper geohashMapper = null; if (enableGeoHash || enableGeohashPrefix) { // TODO: possible also implicitly enable geohash if geohash precision is set geohashMapper = stringField(Names.GEOHASH) .index(true) .tokenized(false) .includeInAll(false) .omitNorms(true) .indexOptions(IndexOptions.DOCS) .build(context); geoPointFieldType.setGeohashEnabled( geohashMapper.fieldType(), geoHashPrecision, enableGeohashPrefix); } context.path().remove(); context.path().pathType(origPathType); // this is important: even if geo points feel like they need to be tokenized to distinguish // lat from lon, we actually want to // store them as a single token. fieldType.setTokenized(false); setupFieldType(context); fieldType.setHasDocValues(false); defaultFieldType.setHasDocValues(false); return new GeoPointFieldMapper( name, fieldType, defaultFieldType, context.indexSettings(), origPathType, latMapper, lonMapper, geohashMapper, multiFieldsBuilder.build(this, context)); }