|
29 | 29 | import org.elasticsearch.common.xcontent.XContentParser; |
30 | 30 | import org.elasticsearch.common.xcontent.XContentType; |
31 | 31 | import org.elasticsearch.common.xcontent.json.JsonXContent; |
| 32 | +import org.elasticsearch.index.mapper.CompletionFieldMapper.CompletionFieldType; |
32 | 33 | import org.elasticsearch.index.mapper.DocumentMapper; |
33 | 34 | import org.elasticsearch.index.mapper.FieldMapper; |
34 | 35 | import org.elasticsearch.index.mapper.MappedFieldType; |
@@ -673,6 +674,31 @@ public void testQueryContextParsingMixedHavingNULL() throws Exception { |
673 | 674 | Exception e = expectThrows(ElasticsearchParseException.class, () -> mapping.parseQueryContext(createParseContext(parser))); |
674 | 675 | assertEquals("category context must be an object, string, number or boolean", e.getMessage()); |
675 | 676 | } |
| 677 | + |
| 678 | + public void testUnknownQueryContextParsing() throws Exception { |
| 679 | + String mapping = jsonBuilder().startObject().startObject("type1") |
| 680 | + .startObject("properties").startObject("completion") |
| 681 | + .field("type", "completion") |
| 682 | + .startArray("contexts") |
| 683 | + .startObject() |
| 684 | + .field("name", "ctx") |
| 685 | + .field("type", "category") |
| 686 | + .endObject() |
| 687 | + .startObject() |
| 688 | + .field("name", "type") |
| 689 | + .field("type", "category") |
| 690 | + .endObject() |
| 691 | + .endArray() |
| 692 | + .endObject().endObject() |
| 693 | + .endObject().endObject().string(); |
| 694 | + |
| 695 | + DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping)); |
| 696 | + FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion"); |
| 697 | + CompletionFieldType completionFieldType = (CompletionFieldType) fieldMapper.fieldType(); |
| 698 | + |
| 699 | + Exception e = expectThrows(IllegalArgumentException.class, () -> completionFieldType.getContextMappings().get("brand")); |
| 700 | + assertEquals("Unknown context name [brand], must be one of [ctx, type]", e.getMessage()); |
| 701 | + } |
676 | 702 |
|
677 | 703 | public void testParsingContextFromDocument() throws Exception { |
678 | 704 | CategoryContextMapping mapping = ContextBuilder.category("cat").field("category").build(); |
|
0 commit comments