|
19 | 19 |
|
20 | 20 | package org.elasticsearch.index.mapper;
|
21 | 21 |
|
| 22 | +import org.apache.lucene.index.IndexableField; |
| 23 | +import org.apache.lucene.util.BytesRef; |
22 | 24 | import org.elasticsearch.Version;
|
23 | 25 | import org.elasticsearch.cluster.metadata.IndexMetaData;
|
24 | 26 | import org.elasticsearch.common.Strings;
|
|
37 | 39 | import org.elasticsearch.test.InternalSettingsPlugin;
|
38 | 40 |
|
39 | 41 | import java.io.IOException;
|
| 42 | +import java.math.BigDecimal; |
| 43 | +import java.math.BigInteger; |
40 | 44 | import java.nio.charset.StandardCharsets;
|
41 | 45 | import java.util.ArrayList;
|
42 | 46 | import java.util.Collection;
|
@@ -706,6 +710,62 @@ public void testMappedNullValue() throws Exception {
|
706 | 710 | assertEquals(0, doc.rootDoc().getFields("foo").length);
|
707 | 711 | }
|
708 | 712 |
|
| 713 | + public void testDynamicBigInteger() throws Exception { |
| 714 | + DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser(); |
| 715 | + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() |
| 716 | + .startObject("type") |
| 717 | + .startArray("dynamic_templates").startObject() |
| 718 | + .startObject("big-integer-to-keyword") |
| 719 | + .field("match", "big-*") |
| 720 | + .field("match_mapping_type", "long") |
| 721 | + .startObject("mapping").field("type", "keyword").endObject() |
| 722 | + .endObject() |
| 723 | + .endObject().endArray() |
| 724 | + .endObject() |
| 725 | + .endObject()); |
| 726 | + |
| 727 | + DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping)); |
| 728 | + BigInteger value = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE); |
| 729 | + BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject() |
| 730 | + .field("big-integer", value) |
| 731 | + .endObject()); |
| 732 | + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); |
| 733 | + |
| 734 | + IndexableField[] fields = doc.rootDoc().getFields("big-integer"); |
| 735 | + assertEquals(2, fields.length); |
| 736 | + assertTrue(fields[0].fieldType() instanceof KeywordFieldMapper.KeywordFieldType); |
| 737 | + assertEquals(new BytesRef(value.toString()), fields[0].binaryValue()); |
| 738 | + } |
| 739 | + |
| 740 | + public void testDynamicBigDecimal() throws Exception { |
| 741 | + DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser(); |
| 742 | + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() |
| 743 | + .startObject("type") |
| 744 | + .startArray("dynamic_templates").startObject() |
| 745 | + .startObject("big-decimal-to-scaled-float") |
| 746 | + .field("match", "big-*") |
| 747 | + .field("match_mapping_type", "double") |
| 748 | + .startObject("mapping") |
| 749 | + .field("type", "keyword") |
| 750 | + .endObject() |
| 751 | + .endObject() |
| 752 | + .endObject().endArray() |
| 753 | + .endObject() |
| 754 | + .endObject()); |
| 755 | + |
| 756 | + BigDecimal value = BigDecimal.valueOf(Double.MAX_VALUE).add(BigDecimal.valueOf(10.1)); |
| 757 | + DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping)); |
| 758 | + BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject() |
| 759 | + .field("big-decimal", value) |
| 760 | + .endObject()); |
| 761 | + ParsedDocument doc = mapper.parse(new SourceToParse("test", "type", "1", bytes, XContentType.JSON)); |
| 762 | + |
| 763 | + IndexableField[] fields = doc.rootDoc().getFields("big-decimal"); |
| 764 | + assertEquals(2, fields.length); |
| 765 | + assertTrue(fields[0].fieldType() instanceof KeywordFieldMapper.KeywordFieldType); |
| 766 | + assertEquals(new BytesRef(value.toString()), fields[0].binaryValue()); |
| 767 | + } |
| 768 | + |
709 | 769 | public void testDynamicDottedFieldNameLongArray() throws Exception {
|
710 | 770 | DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser();
|
711 | 771 | String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
0 commit comments