|
|
@@ -18,6 +18,7 @@
|
|
|
*/
|
|
|
package org.elasticsearch.index.mapper;
|
|
|
|
|
|
+import org.apache.lucene.index.IndexableField;
|
|
|
import org.apache.lucene.spatial.prefix.PrefixTreeStrategy;
|
|
|
import org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy;
|
|
|
import org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree;
|
|
|
@@ -26,6 +27,7 @@ import org.elasticsearch.ElasticsearchException;
|
|
|
import org.elasticsearch.ElasticsearchParseException;
|
|
|
import org.elasticsearch.common.Explicit;
|
|
|
import org.elasticsearch.common.Strings;
|
|
|
+import org.elasticsearch.common.bytes.BytesReference;
|
|
|
import org.elasticsearch.common.compress.CompressedXContent;
|
|
|
import org.elasticsearch.common.geo.GeoUtils;
|
|
|
import org.elasticsearch.common.geo.ShapeRelation;
|
|
|
@@ -34,6 +36,7 @@ import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
|
|
import org.elasticsearch.common.xcontent.ToXContent;
|
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
|
+import org.elasticsearch.common.xcontent.XContentType;
|
|
|
import org.elasticsearch.geometry.Point;
|
|
|
import org.elasticsearch.index.query.QueryShardContext;
|
|
|
import org.elasticsearch.plugins.Plugin;
|
|
|
@@ -49,6 +52,7 @@ import java.util.Set;
|
|
|
import static org.elasticsearch.index.mapper.AbstractGeometryFieldMapper.Names.IGNORE_Z_VALUE;
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
+import static org.hamcrest.Matchers.hasSize;
|
|
|
import static org.hamcrest.Matchers.instanceOf;
|
|
|
import static org.hamcrest.Matchers.not;
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
@@ -783,6 +787,43 @@ public class LegacyGeoShapeFieldMapperTests extends FieldMapperTestCase<LegacyGe
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ public void testGeoShapeArrayParsing() throws Exception {
|
|
|
+ String mapping = Strings.toString(XContentFactory.jsonBuilder()
|
|
|
+ .startObject()
|
|
|
+ .startObject("properties")
|
|
|
+ .startObject("location")
|
|
|
+ .field("type", "geo_shape")
|
|
|
+ .field("tree", "quadtree")
|
|
|
+ .endObject()
|
|
|
+ .endObject()
|
|
|
+ .endObject());
|
|
|
+
|
|
|
+ DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser()
|
|
|
+ .parse("_doc", new CompressedXContent(mapping));
|
|
|
+
|
|
|
+ BytesReference arrayedDoc = BytesReference.bytes(XContentFactory.jsonBuilder()
|
|
|
+ .startObject()
|
|
|
+ .startArray("shape")
|
|
|
+ .startObject()
|
|
|
+ .field("type", "Point")
|
|
|
+ .startArray("coordinates").value(176.0).value(15.0).endArray()
|
|
|
+ .endObject()
|
|
|
+ .startObject()
|
|
|
+ .field("type", "Point")
|
|
|
+ .startArray("coordinates").value(76.0).value(-15.0).endArray()
|
|
|
+ .endObject()
|
|
|
+ .endArray()
|
|
|
+ .endObject()
|
|
|
+ );
|
|
|
+
|
|
|
+ SourceToParse sourceToParse = new SourceToParse("test", "1", arrayedDoc, XContentType.JSON);
|
|
|
+ ParsedDocument document = mapper.parse(sourceToParse);
|
|
|
+ assertThat(document.docs(), hasSize(1));
|
|
|
+ IndexableField[] fields = document.docs().get(0).getFields("shape.type");
|
|
|
+ assertThat(fields.length, equalTo(2));
|
|
|
+ assertFieldWarnings("tree");
|
|
|
+ }
|
|
|
+
|
|
|
public String toXContentString(LegacyGeoShapeFieldMapper mapper, boolean includeDefaults) throws IOException {
|
|
|
XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
|
|
|
ToXContent.Params params;
|