Search in sources :

Example 11 with DocumentMapperParser

use of org.elasticsearch.index.mapper.DocumentMapperParser in project elasticsearch-opennlp-plugin by spinscale.

the class OpenNlpMappingTest method setupMapperParser.

@Before
public void setupMapperParser() {
    Index index = new Index("test");
    Map<String, AnalyzerProviderFactory> analyzerFactoryFactories = Maps.newHashMap();
    analyzerFactoryFactories.put("keyword", new PreBuiltAnalyzerProviderFactory("keyword", AnalyzerScope.INDEX, new KeywordAnalyzer()));
    AnalysisService analysisService = new AnalysisService(index, ImmutableSettings.Builder.EMPTY_SETTINGS, null, analyzerFactoryFactories, null, null, null);
    mapperParser = new DocumentMapperParser(index, analysisService, new PostingsFormatService(index), new SimilarityLookupService(index, ImmutableSettings.Builder.EMPTY_SETTINGS));
    Settings settings = settingsBuilder().put("opennlp.models.name.file", "src/test/resources/models/en-ner-person.bin").put("opennlp.models.date.file", "src/test/resources/models/en-ner-date.bin").put("opennlp.models.location.file", "src/test/resources/models/en-ner-location.bin").build();
    LogConfigurator.configure(settings);
    OpenNlpService openNlpService = new OpenNlpService(settings);
    openNlpService.start();
    mapperParser.putTypeParser(OpenNlpMapper.CONTENT_TYPE, new OpenNlpMapper.TypeParser(analysisService, openNlpService));
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) PostingsFormatService(org.elasticsearch.index.codec.postingsformat.PostingsFormatService) PreBuiltAnalyzerProviderFactory(org.elasticsearch.index.analysis.PreBuiltAnalyzerProviderFactory) Index(org.elasticsearch.index.Index) Matchers.containsString(org.hamcrest.Matchers.containsString) AnalyzerProviderFactory(org.elasticsearch.index.analysis.AnalyzerProviderFactory) PreBuiltAnalyzerProviderFactory(org.elasticsearch.index.analysis.PreBuiltAnalyzerProviderFactory) DocumentMapperParser(org.elasticsearch.index.mapper.DocumentMapperParser) OpenNlpService(org.elasticsearch.service.opennlp.OpenNlpService) SimilarityLookupService(org.elasticsearch.index.similarity.SimilarityLookupService) OpenNlpMapper(org.elasticsearch.index.mapper.opennlp.OpenNlpMapper) AnalysisService(org.elasticsearch.index.analysis.AnalysisService) ImmutableSettings(org.elasticsearch.common.settings.ImmutableSettings) Settings(org.elasticsearch.common.settings.Settings) Before(org.junit.Before)

Example 12 with DocumentMapperParser

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

the class SimilarityTests method testSimilarityDefaultBackCompat.

public void testSimilarityDefaultBackCompat() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field1").field("similarity", "default").field("type", "text").endObject().endObject().endObject().endObject().string();
    Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_2_2_0)).build();
    DocumentMapperParser parser = createIndex("test_v2.x", settings).mapperService().documentMapperParser();
    DocumentMapper documentMapper = parser.parse("type", new CompressedXContent(mapping));
    assertThat(documentMapper.mappers().getMapper("field1").fieldType().similarity(), instanceOf(ClassicSimilarityProvider.class));
    assertThat(documentMapper.mappers().getMapper("field1").fieldType().similarity().name(), equalTo("classic"));
    parser = createIndex("test_v3.x").mapperService().documentMapperParser();
    try {
        parser.parse("type", new CompressedXContent(mapping));
        fail("Expected MappingParsingException");
    } catch (MapperParsingException e) {
        assertThat(e.getMessage(), equalTo("Unknown Similarity type [default] for field [field1]"));
    }
}
Also used : MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) DocumentMapperParser(org.elasticsearch.index.mapper.DocumentMapperParser) Settings(org.elasticsearch.common.settings.Settings)

Example 13 with DocumentMapperParser

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

the class DocumentMapperMergeTests method testMergeObjectAndNested.

public void testMergeObjectAndNested() throws Exception {
    DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
    String objectMapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("obj").field("type", "object").endObject().endObject().endObject().endObject().string();
    DocumentMapper objectMapper = parser.parse("type1", new CompressedXContent(objectMapping));
    String nestedMapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("obj").field("type", "nested").endObject().endObject().endObject().endObject().string();
    DocumentMapper nestedMapper = parser.parse("type1", new CompressedXContent(nestedMapping));
    try {
        objectMapper.merge(nestedMapper.mapping(), false);
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("object mapping [obj] can't be changed from non-nested to nested"));
    }
    try {
        nestedMapper.merge(objectMapper.mapping(), false);
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("object mapping [obj] can't be changed from nested to non-nested"));
    }
}
Also used : DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString) DocumentMapperParser(org.elasticsearch.index.mapper.DocumentMapperParser)

Example 14 with DocumentMapperParser

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

the class DocumentMapperParserTests method testFieldNameWithDotsConflict.

public void testFieldNameWithDotsConflict() throws Exception {
    IndexService indexService = createIndex("test");
    DocumentMapperParser mapperParser = indexService.mapperService().documentMapperParser();
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("foo").field("type", "text").endObject().startObject("foo.baz").field("type", "keyword").endObject().endObject().endObject().endObject().string();
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> mapperParser.parse("type", new CompressedXContent(mapping)));
    assertTrue(e.getMessage(), e.getMessage().contains("mapper [foo] of different type"));
}
Also used : IndexService(org.elasticsearch.index.IndexService) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) DocumentMapperParser(org.elasticsearch.index.mapper.DocumentMapperParser)

Example 15 with DocumentMapperParser

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

the class DocumentMapperParserTests method testFieldNameWithDeepDots.

public void testFieldNameWithDeepDots() 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").startObject("properties").startObject("deep.field").field("type", "keyword").endObject().endObject().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.deep.field"));
    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)

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