Skip to content

Commit

Permalink
HSEARCH-2434 Don't treat spatial hash fields specially when translati…
Browse files Browse the repository at this point in the history
…ng to the ES schema

There is no reason to do that, and it forces us to implement yet another
special case for ES5.
  • Loading branch information
yrodiere committed Mar 21, 2017
1 parent ca85bd7 commit 837d79e
Showing 1 changed file with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,22 @@ private void addPropertyMapping(ElasticsearchMappingBuilder mappingBuilder, Elas
BridgeDefinedField bridgeDefinedField) {
String propertyPath = bridgeDefinedField.getAbsoluteName();

if ( !SpatialHelper.isSpatialField( propertyPath ) ) {
if ( SpatialHelper.isSpatialFieldLongitude( propertyPath ) ) {
// we ignore the longitude field, we will create the geo_point mapping only once with the latitude field
return;
}
else if ( SpatialHelper.isSpatialFieldLatitude( propertyPath ) ) {
// we only add the geo_point for the latitude field
PropertyMapping propertyMapping = new PropertyMapping();

propertyMapping.setType( DataType.GEO_POINT );

// in this case, the spatial field has precedence over an already defined field
mappingBuilder.setPropertyAbsolute( SpatialHelper.stripSpatialFieldSuffix( propertyPath ), propertyMapping );
}
else {
// This includes the fields potentially created for the spatial hash queries

// we don't overwrite already defined fields. Typically, in the case of spatial, the geo_point field
// is defined before the double field and we want to keep the geo_point one
if ( !mappingBuilder.hasPropertyAbsolute( propertyPath ) ) {
Expand All @@ -211,29 +226,6 @@ private void addPropertyMapping(ElasticsearchMappingBuilder mappingBuilder, Elas
addDynamicOption( bridgeDefinedField, propertyMapping );
}
}
else {
if ( SpatialHelper.isSpatialFieldLongitude( propertyPath ) ) {
// we ignore the longitude field, we will create the geo_point mapping only once with the latitude field
return;
}
else if ( SpatialHelper.isSpatialFieldLatitude( propertyPath ) ) {
// we only add the geo_point for the latitude field
PropertyMapping propertyMapping = new PropertyMapping();

propertyMapping.setType( DataType.GEO_POINT );

// in this case, the spatial field has precedence over an already defined field
mappingBuilder.setPropertyAbsolute( SpatialHelper.stripSpatialFieldSuffix( propertyPath ), propertyMapping );
}
else {
// the fields potentially created for the spatial hash queries
PropertyMapping propertyMapping = new PropertyMapping();
propertyMapping.setType( DataType.STRING );
propertyMapping.setIndex( IndexType.NOT_ANALYZED );

mappingBuilder.setPropertyAbsolute( propertyPath, propertyMapping );
}
}
}

private void addDynamicOption(BridgeDefinedField bridgeDefinedField, TypeMapping propertyMapping) {
Expand Down

0 comments on commit 837d79e

Please sign in to comment.