From ef33a74286f90c3b0b0057b1d4c8b68bb381bc8b Mon Sep 17 00:00:00 2001 From: Nicholas Knize Date: Tue, 29 Dec 2015 16:09:00 -0600 Subject: [PATCH] Fix multi-field support for GeoPoint types This commit fixes multiField support for GeoPointFieldMapper by passing an externalValueContext to the multiField parser. Unit testing is added for multi field coverage. --- .../mapper/geo/BaseGeoPointFieldMapper.java | 2 +- .../mapper/geo/GeoPointFieldMapperTests.java | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/index/mapper/geo/BaseGeoPointFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/geo/BaseGeoPointFieldMapper.java index 11683ee9a8d..52202fac716 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/geo/BaseGeoPointFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/geo/BaseGeoPointFieldMapper.java @@ -412,7 +412,7 @@ public abstract class BaseGeoPointFieldMapper extends FieldMapper implements Arr latMapper.parse(context.createExternalValueContext(point.lat())); lonMapper.parse(context.createExternalValueContext(point.lon())); } - multiFields.parse(this, context); + multiFields.parse(this, context.createExternalValueContext(point)); } @Override diff --git a/core/src/test/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapperTests.java index af39f45fa8d..d89e27ffb69 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/geo/GeoPointFieldMapperTests.java @@ -26,6 +26,7 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Priority; import org.elasticsearch.common.compress.CompressedXContent; +import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; @@ -37,6 +38,7 @@ import org.elasticsearch.index.mapper.ParsedDocument; import org.elasticsearch.search.SearchHitField; import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.test.VersionUtils; +import org.elasticsearch.test.geo.RandomGeoGenerator; import java.util.List; import java.util.Map; @@ -787,4 +789,32 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase { assertEquals("dr5regy6rc6y".substring(0, numHashes-i), hashes.get(i)); } } + + public void testMultiField() throws Exception { + int numDocs = randomIntBetween(10, 100); + String mapping = XContentFactory.jsonBuilder().startObject().startObject("pin").startObject("properties").startObject("location") + .field("type", "geo_point").startObject("fields") + .startObject("geohash").field("type", "geo_point").field("geohash_precision", 12).field("geohash_prefix", true).endObject() + .startObject("latlon").field("type", "geo_point").field("lat_lon", true).endObject().endObject() + .endObject().endObject().endObject().endObject().string(); + CreateIndexRequestBuilder mappingRequest = client().admin().indices().prepareCreate("test") + .addMapping("pin", mapping); + mappingRequest.execute().actionGet(); + + // create index and add random test points + client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); + for (int i=0; i