Search in sources :

Example 6 with MapperParsingException

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"));
    }
}
Also used : MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) DocumentMapperParser(org.elasticsearch.index.mapper.DocumentMapperParser)

Example 7 with MapperParsingException

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"));
    }
}
Also used : MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) DocumentMapperParser(org.elasticsearch.index.mapper.DocumentMapperParser)

Example 8 with MapperParsingException

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 '.'"));
    }
}
Also used : MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) MapperService(org.elasticsearch.index.mapper.MapperService)

Example 9 with MapperParsingException

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"));
    }
}
Also used : MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent)

Example 10 with MapperParsingException

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());
}
Also used : MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) DocumentMapperParser(org.elasticsearch.index.mapper.DocumentMapperParser)

Aggregations

MapperParsingException (org.elasticsearch.index.mapper.MapperParsingException)35 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)16 Matchers.containsString (org.hamcrest.Matchers.containsString)11 IndexService (org.elasticsearch.index.IndexService)7 Settings (org.elasticsearch.common.settings.Settings)5 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)5 Index (org.elasticsearch.index.Index)4 MapperService (org.elasticsearch.index.mapper.MapperService)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 DocumentMapperParser (org.elasticsearch.index.mapper.DocumentMapperParser)3 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 GetIndexTemplatesResponse (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)2 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)2 ValidationException (org.elasticsearch.common.ValidationException)2 IndexScopedSettings (org.elasticsearch.common.settings.IndexScopedSettings)2 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)2