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));
}
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]"));
}
}
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"));
}
}
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"));
}
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"));
}
Aggregations