|
@@ -13,6 +13,7 @@ import org.elasticsearch.common.bytes.BytesReference;
|
|
|
import org.elasticsearch.common.xcontent.ToXContent;
|
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
import org.elasticsearch.common.xcontent.XContentParser;
|
|
|
+import org.elasticsearch.common.xcontent.XContentType;
|
|
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
|
|
import org.elasticsearch.index.mapper.ParseContext.Document;
|
|
|
import org.hamcrest.Matchers;
|
|
@@ -624,4 +625,93 @@ public class CopyToMapperTests extends MapperServiceTestCase {
|
|
|
assertThat(e.getMessage(),
|
|
|
Matchers.containsString("[copy_to] may not be used to copy from a multi-field: [field.bar]"));
|
|
|
}
|
|
|
+
|
|
|
+ public void testCopyToDateRangeFailure() throws Exception {
|
|
|
+ DocumentMapper docMapper = createDocumentMapper(topMapping(b -> {
|
|
|
+ b.startObject("properties");
|
|
|
+ {
|
|
|
+ b.startObject("date_copy")
|
|
|
+ .field("type", "date_range")
|
|
|
+ .endObject()
|
|
|
+ .startObject("date")
|
|
|
+ .field("type", "date_range")
|
|
|
+ .array("copy_to", "date_copy")
|
|
|
+ .endObject();
|
|
|
+ }
|
|
|
+ b.endObject();
|
|
|
+ }));
|
|
|
+
|
|
|
+ BytesReference json = BytesReference.bytes(jsonBuilder().startObject()
|
|
|
+ .startObject("date")
|
|
|
+ .field("gte", "2019-11-10T01:00:00.000Z")
|
|
|
+ .field("lt", "2019-11-11T01:00:00.000Z")
|
|
|
+ .endObject()
|
|
|
+ .endObject());
|
|
|
+
|
|
|
+ MapperParsingException ex = expectThrows(MapperParsingException.class, () -> docMapper.parse(new SourceToParse("test", "1", json,
|
|
|
+ XContentType.JSON)).rootDoc());
|
|
|
+ assertEquals(
|
|
|
+ "Cannot copy field [date] to fields [date_copy]. Copy-to currently only works for value-type fields, not objects.",
|
|
|
+ ex.getMessage()
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testCopyToGeoPoint() throws Exception {
|
|
|
+ DocumentMapper docMapper = createDocumentMapper(topMapping(b -> {
|
|
|
+ b.startObject("properties");
|
|
|
+ {
|
|
|
+ b.startObject("geopoint_copy")
|
|
|
+ .field("type", "geo_point")
|
|
|
+ .endObject()
|
|
|
+ .startObject("geopoint")
|
|
|
+ .field("type", "geo_point")
|
|
|
+ .array("copy_to", "geopoint_copy")
|
|
|
+ .endObject();
|
|
|
+ }
|
|
|
+ b.endObject();
|
|
|
+ }));
|
|
|
+ // copy-to works for value-type representations
|
|
|
+ {
|
|
|
+ for (String value : List.of("41.12,-71.34", "drm3btev3e86", "POINT (-71.34 41.12)")) {
|
|
|
+ BytesReference json = BytesReference.bytes(jsonBuilder().startObject().field("geopoint", value).endObject());
|
|
|
+
|
|
|
+ ParseContext.Document doc = docMapper.parse(new SourceToParse("test", "1", json, XContentType.JSON)).rootDoc();
|
|
|
+
|
|
|
+ IndexableField[] fields = doc.getFields("geopoint");
|
|
|
+ assertThat(fields.length, equalTo(2));
|
|
|
+
|
|
|
+ fields = doc.getFields("geopoint_copy");
|
|
|
+ assertThat(fields.length, equalTo(2));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // check failure for object/array type representations
|
|
|
+ {
|
|
|
+ BytesReference json = BytesReference.bytes(
|
|
|
+ jsonBuilder().startObject().startObject("geopoint").field("lat", 41.12).field("lon", -71.34).endObject().endObject()
|
|
|
+ );
|
|
|
+
|
|
|
+ MapperParsingException ex = expectThrows(
|
|
|
+ MapperParsingException.class,
|
|
|
+ () -> docMapper.parse(new SourceToParse("test", "1", json, XContentType.JSON)).rootDoc()
|
|
|
+ );
|
|
|
+ assertEquals(
|
|
|
+ "Cannot copy field [geopoint] to fields [geopoint_copy]. Copy-to currently only works for value-type fields, not objects.",
|
|
|
+ ex.getMessage()
|
|
|
+ );
|
|
|
+ }
|
|
|
+ {
|
|
|
+ BytesReference json = BytesReference.bytes(
|
|
|
+ jsonBuilder().startObject().array("geopoint", new double[] { -71.34, 41.12 }).endObject()
|
|
|
+ );
|
|
|
+
|
|
|
+ MapperParsingException ex = expectThrows(
|
|
|
+ MapperParsingException.class,
|
|
|
+ () -> docMapper.parse(new SourceToParse("test", "1", json, XContentType.JSON)).rootDoc()
|
|
|
+ );
|
|
|
+ assertEquals(
|
|
|
+ "Cannot copy field [geopoint] to fields [geopoint_copy]. Copy-to currently only works for value-type fields, not objects.",
|
|
|
+ ex.getMessage()
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|