Search in sources :

Example 6 with DocumentMapperParser

use of org.elasticsearch.index.mapper.DocumentMapperParser in project elasticsearch by elastic.

the class DocumentMapperParserTests method testFieldNameWithDots.

public void testFieldNameWithDots() throws Exception {
    IndexService indexService = createIndex("test");
    DocumentMapperParser mapperParser = indexService.mapperService().documentMapperParser();
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("foo.bar").field("type", "text").endObject().startObject("foo.baz").field("type", "keyword").endObject().endObject().endObject().endObject().string();
    DocumentMapper docMapper = mapperParser.parse("type", new CompressedXContent(mapping));
    assertNotNull(docMapper.mappers().getMapper("foo.bar"));
    assertNotNull(docMapper.mappers().getMapper("foo.baz"));
    assertNotNull(docMapper.objectMappers().get("foo"));
}
Also used : IndexService(org.elasticsearch.index.IndexService) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) DocumentMapperParser(org.elasticsearch.index.mapper.DocumentMapperParser)

Example 7 with DocumentMapperParser

use of org.elasticsearch.index.mapper.DocumentMapperParser in project elasticsearch by elastic.

the class DocumentMapperParserTests method testTypeLevel.

public void testTypeLevel() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
    DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
    assertThat(mapper.type(), equalTo("type"));
}
Also used : DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) DocumentMapperParser(org.elasticsearch.index.mapper.DocumentMapperParser)

Example 8 with DocumentMapperParser

use of org.elasticsearch.index.mapper.DocumentMapperParser 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 9 with DocumentMapperParser

use of org.elasticsearch.index.mapper.DocumentMapperParser 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 10 with DocumentMapperParser

use of org.elasticsearch.index.mapper.DocumentMapperParser 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

DocumentMapperParser (org.elasticsearch.index.mapper.DocumentMapperParser)16 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)14 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)10 Matchers.containsString (org.hamcrest.Matchers.containsString)7 Settings (org.elasticsearch.common.settings.Settings)4 IndexService (org.elasticsearch.index.IndexService)4 MapperParsingException (org.elasticsearch.index.mapper.MapperParsingException)4 Version (org.elasticsearch.Version)2 QueryShardContext (org.elasticsearch.index.query.QueryShardContext)2 Before (org.junit.Before)2 KeywordAnalyzer (org.apache.lucene.analysis.core.KeywordAnalyzer)1 ImmutableSettings (org.elasticsearch.common.settings.ImmutableSettings)1 Index (org.elasticsearch.index.Index)1 AnalysisService (org.elasticsearch.index.analysis.AnalysisService)1 AnalyzerProviderFactory (org.elasticsearch.index.analysis.AnalyzerProviderFactory)1 PreBuiltAnalyzerProviderFactory (org.elasticsearch.index.analysis.PreBuiltAnalyzerProviderFactory)1 PostingsFormatService (org.elasticsearch.index.codec.postingsformat.PostingsFormatService)1 OpenNlpMapper (org.elasticsearch.index.mapper.opennlp.OpenNlpMapper)1 SimilarityLookupService (org.elasticsearch.index.similarity.SimilarityLookupService)1 MapperRegistry (org.elasticsearch.indices.mapper.MapperRegistry)1