|
19 | 19 |
|
20 | 20 | package org.elasticsearch.index.mapper;
|
21 | 21 |
|
| 22 | +import org.apache.lucene.document.FieldType; |
22 | 23 | import org.apache.lucene.index.DocValuesType;
|
23 | 24 | import org.apache.lucene.index.IndexOptions;
|
24 | 25 | import org.apache.lucene.index.IndexableField;
|
@@ -595,6 +596,80 @@ public void testEmptyName() throws IOException {
|
595 | 596 | assertThat(e.getMessage(), containsString("name cannot be empty string"));
|
596 | 597 | }
|
597 | 598 |
|
| 599 | + public void testIndexPrefixIndexTypes() throws IOException { |
| 600 | + QueryShardContext queryShardContext = indexService.newQueryShardContext( |
| 601 | + randomInt(20), null, () -> { |
| 602 | + throw new UnsupportedOperationException(); |
| 603 | + }, null); |
| 604 | + |
| 605 | + { |
| 606 | + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") |
| 607 | + .startObject("properties").startObject("field") |
| 608 | + .field("type", "text") |
| 609 | + .field("analyzer", "english") |
| 610 | + .startObject("index_prefix").endObject() |
| 611 | + .field("index_options", "offsets") |
| 612 | + .endObject().endObject().endObject().endObject()); |
| 613 | + |
| 614 | + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); |
| 615 | + |
| 616 | + FieldMapper prefix = mapper.mappers().getMapper("field._index_prefix"); |
| 617 | + FieldType ft = prefix.fieldType; |
| 618 | + assertEquals(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS, ft.indexOptions()); |
| 619 | + } |
| 620 | + |
| 621 | + { |
| 622 | + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") |
| 623 | + .startObject("properties").startObject("field") |
| 624 | + .field("type", "text") |
| 625 | + .field("analyzer", "english") |
| 626 | + .startObject("index_prefix").endObject() |
| 627 | + .field("index_options", "positions") |
| 628 | + .endObject().endObject().endObject().endObject()); |
| 629 | + |
| 630 | + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); |
| 631 | + |
| 632 | + FieldMapper prefix = mapper.mappers().getMapper("field._index_prefix"); |
| 633 | + FieldType ft = prefix.fieldType; |
| 634 | + assertEquals(IndexOptions.DOCS, ft.indexOptions()); |
| 635 | + assertFalse(ft.storeTermVectors()); |
| 636 | + } |
| 637 | + |
| 638 | + { |
| 639 | + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") |
| 640 | + .startObject("properties").startObject("field") |
| 641 | + .field("type", "text") |
| 642 | + .field("analyzer", "english") |
| 643 | + .startObject("index_prefix").endObject() |
| 644 | + .field("term_vector", "with_positions_offsets") |
| 645 | + .endObject().endObject().endObject().endObject()); |
| 646 | + |
| 647 | + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); |
| 648 | + |
| 649 | + FieldMapper prefix = mapper.mappers().getMapper("field._index_prefix"); |
| 650 | + FieldType ft = prefix.fieldType; |
| 651 | + assertEquals(IndexOptions.DOCS, ft.indexOptions()); |
| 652 | + assertTrue(ft.storeTermVectorOffsets()); |
| 653 | + } |
| 654 | + |
| 655 | + { |
| 656 | + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") |
| 657 | + .startObject("properties").startObject("field") |
| 658 | + .field("type", "text") |
| 659 | + .field("analyzer", "english") |
| 660 | + .startObject("index_prefix").endObject() |
| 661 | + .field("term_vector", "with_positions") |
| 662 | + .endObject().endObject().endObject().endObject()); |
| 663 | + |
| 664 | + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); |
| 665 | + |
| 666 | + FieldMapper prefix = mapper.mappers().getMapper("field._index_prefix"); |
| 667 | + FieldType ft = prefix.fieldType; |
| 668 | + assertEquals(IndexOptions.DOCS, ft.indexOptions()); |
| 669 | + assertFalse(ft.storeTermVectorOffsets()); |
| 670 | + } |
| 671 | + } |
| 672 | + |
598 | 673 | public void testIndexPrefixMapping() throws IOException {
|
599 | 674 |
|
600 | 675 | QueryShardContext queryShardContext = indexService.newQueryShardContext(
|
|
0 commit comments