use of org.elasticsearch.index.mapper.MapperParsingException in project elasticsearch by elastic.
the class MultiFieldTests method testObjectFieldNotAllowed.
public void testObjectFieldNotAllowed() throws Exception {
String mapping = jsonBuilder().startObject().startObject("type").startObject("properties").startObject("my_field").field("type", "text").startObject("fields").startObject("multi").field("type", "object").endObject().endObject().endObject().endObject().endObject().endObject().string();
final DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
try {
parser.parse("type", new CompressedXContent(mapping));
fail("expected mapping parse failure");
} catch (MapperParsingException e) {
assertTrue(e.getMessage().contains("cannot be used in multi field"));
}
}
use of org.elasticsearch.index.mapper.MapperParsingException in project elasticsearch by elastic.
the class MultiFieldTests method testNestedFieldNotAllowed.
public void testNestedFieldNotAllowed() throws Exception {
String mapping = jsonBuilder().startObject().startObject("type").startObject("properties").startObject("my_field").field("type", "text").startObject("fields").startObject("multi").field("type", "nested").endObject().endObject().endObject().endObject().endObject().endObject().string();
final DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
try {
parser.parse("type", new CompressedXContent(mapping));
fail("expected mapping parse failure");
} catch (MapperParsingException e) {
assertTrue(e.getMessage().contains("cannot be used in multi field"));
}
}
use of org.elasticsearch.index.mapper.MapperParsingException in project elasticsearch by elastic.
the class MultiFieldTests method testMultiFieldWithDot.
public void testMultiFieldWithDot() throws IOException {
XContentBuilder mapping = jsonBuilder();
mapping.startObject().startObject("my_type").startObject("properties").startObject("city").field("type", "text").startObject("fields").startObject("raw.foo").field("type", "text").field("index", "not_analyzed").endObject().endObject().endObject().endObject().endObject().endObject();
MapperService mapperService = createIndex("test").mapperService();
try {
mapperService.documentMapperParser().parse("my_type", new CompressedXContent(mapping.string()));
fail("this should throw an exception because one field contains a dot");
} catch (MapperParsingException e) {
assertThat(e.getMessage(), equalTo("Field name [raw.foo] which is a multi field of [city] cannot contain '.'"));
}
}
use of org.elasticsearch.index.mapper.MapperParsingException in project elasticsearch by elastic.
the class IdFieldMapperTests method testIncludeInObjectNotAllowed.
public void testIncludeInObjectNotAllowed() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
try {
docMapper.parse(SourceToParse.source("test", "type", "1", XContentFactory.jsonBuilder().startObject().field("_id", "1").endObject().bytes(), XContentType.JSON));
fail("Expected failure to parse metadata field");
} catch (MapperParsingException e) {
assertTrue(e.getMessage(), e.getMessage().contains("Field [_id] is a metadata field and cannot be added inside a document"));
}
}
use of org.elasticsearch.index.mapper.MapperParsingException in project elasticsearch by elastic.
the class IndexFieldMapperTests method testIndexNotConfigurable.
public void testIndexNotConfigurable() throws IOException {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("_index").endObject().endObject().endObject().string();
DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
MapperParsingException e = expectThrows(MapperParsingException.class, () -> parser.parse("type", new CompressedXContent(mapping)));
assertEquals("_index is not configurable", e.getMessage());
}
Aggregations