当前位置: 首页>>代码示例>>Java>>正文


Java DocumentMapperParser类代码示例

本文整理汇总了Java中org.elasticsearch.index.mapper.DocumentMapperParser的典型用法代码示例。如果您正苦于以下问题:Java DocumentMapperParser类的具体用法?Java DocumentMapperParser怎么用?Java DocumentMapperParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DocumentMapperParser类属于org.elasticsearch.index.mapper包,在下文中一共展示了DocumentMapperParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testEmptyName

import org.elasticsearch.index.mapper.DocumentMapperParser; //导入依赖的package包/类
public void testEmptyName() throws Exception {
    // after 5.x
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
        .startObject("properties").startObject("").field("type", "percolator").endObject().endObject()
        .endObject().endObject().string();
    DocumentMapperParser parser = mapperService.documentMapperParser();

    IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
        () -> parser.parse("type1", new CompressedXContent(mapping))
    );
    assertThat(e.getMessage(), containsString("name cannot be empty string"));

    // before 5.x
    Version oldVersion = VersionUtils.randomVersionBetween(getRandom(), Version.V_2_0_0, Version.V_2_3_5);
    Settings oldIndexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, oldVersion).build();
    DocumentMapperParser parser2x = createIndex("test_old", oldIndexSettings).mapperService().documentMapperParser();

    DocumentMapper defaultMapper = parser2x.parse("type1", new CompressedXContent(mapping));
    assertEquals(mapping, defaultMapper.mappingSource().string());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:PercolatorFieldMapperTests.java

示例2: load

import org.elasticsearch.index.mapper.DocumentMapperParser; //导入依赖的package包/类
private static ContextMapping load(Map<String, Object> contextConfig, Version indexVersionCreated) {
    String name = extractRequiredValue(contextConfig, FIELD_NAME);
    String type = extractRequiredValue(contextConfig, FIELD_TYPE);
    final ContextMapping contextMapping;
    switch (Type.fromString(type)) {
        case CATEGORY:
            contextMapping = CategoryContextMapping.load(name, contextConfig);
            break;
        case GEO:
            contextMapping = GeoContextMapping.load(name, contextConfig);
            break;
        default:
            throw new ElasticsearchParseException("unknown context type[" + type + "]");
    }
    DocumentMapperParser.checkNoRemainingFields(name, contextConfig, indexVersionCreated);
    return contextMapping;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:ContextMappings.java

示例3: test1Merge

import org.elasticsearch.index.mapper.DocumentMapperParser; //导入依赖的package包/类
public void test1Merge() throws Exception {

        String stage1Mapping = XContentFactory.jsonBuilder().startObject().startObject("person").startObject("properties")
                .startObject("name").field("type", "text").endObject()
                .endObject().endObject().endObject().string();
        DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
        DocumentMapper stage1 = parser.parse("person", new CompressedXContent(stage1Mapping));
        String stage2Mapping = XContentFactory.jsonBuilder().startObject().startObject("person").startObject("properties")
                .startObject("name").field("type", "text").endObject()
                .startObject("age").field("type", "integer").endObject()
                .startObject("obj1").startObject("properties").startObject("prop1").field("type", "integer").endObject().endObject().endObject()
                .endObject().endObject().endObject().string();
        DocumentMapper stage2 = parser.parse("person", new CompressedXContent(stage2Mapping));

        DocumentMapper merged = stage1.merge(stage2.mapping(), false);
        // stage1 mapping should not have been modified
        assertThat(stage1.mappers().smartNameFieldMapper("age"), nullValue());
        assertThat(stage1.mappers().smartNameFieldMapper("obj1.prop1"), nullValue());
        // but merged should
        assertThat(merged.mappers().smartNameFieldMapper("age"), notNullValue());
        assertThat(merged.mappers().smartNameFieldMapper("obj1.prop1"), notNullValue());
    }
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:DocumentMapperMergeTests.java

示例4: testMergeSearchAnalyzer

import org.elasticsearch.index.mapper.DocumentMapperParser; //导入依赖的package包/类
public void testMergeSearchAnalyzer() throws Exception {
    DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
    String mapping1 = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "text").field("analyzer", "standard").field("search_analyzer", "whitespace").endObject().endObject()
            .endObject().endObject().string();
    String mapping2 = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "text").field("analyzer", "standard").field("search_analyzer", "keyword").endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper existing = parser.parse("type", new CompressedXContent(mapping1));
    DocumentMapper changed = parser.parse("type", new CompressedXContent(mapping2));

    assertThat(((NamedAnalyzer) existing.mappers().getMapper("field").fieldType().searchAnalyzer()).name(), equalTo("whitespace"));
    DocumentMapper merged = existing.merge(changed.mapping(), false);

    assertThat(((NamedAnalyzer) merged.mappers().getMapper("field").fieldType().searchAnalyzer()).name(), equalTo("keyword"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:DocumentMapperMergeTests.java

示例5: loadMapping

import org.elasticsearch.index.mapper.DocumentMapperParser; //导入依赖的package包/类
protected static ContextMapping loadMapping(String name, Map<String, Object> config, Version indexVersionCreated)
        throws ElasticsearchParseException {
    final Object argType = config.get(ContextMapping.FIELD_TYPE);

    if (argType == null) {
        throw new ElasticsearchParseException("missing [{}] in context mapping", ContextMapping.FIELD_TYPE);
    }

    final String type = argType.toString();
    ContextMapping contextMapping;
    if (GeolocationContextMapping.TYPE.equals(type)) {
        contextMapping = GeolocationContextMapping.load(name, config);
    } else if (CategoryContextMapping.TYPE.equals(type)) {
        contextMapping = CategoryContextMapping.load(name, config);
    } else {
        throw new ElasticsearchParseException("unknown context type [{}]", type);
    }
    config.remove(ContextMapping.FIELD_TYPE);
    DocumentMapperParser.checkNoRemainingFields(name, config, indexVersionCreated);

    return contextMapping;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:ContextBuilder.java

示例6: newDocumentMapperParser

import org.elasticsearch.index.mapper.DocumentMapperParser; //导入依赖的package包/类
public static DocumentMapperParser newDocumentMapperParser(Settings settings) {
    Settings forcedSettings = Settings.builder()
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .put(settings)
            .build();
    SimilarityLookupService similarityLookupService = newSimilarityLookupService(forcedSettings);
    Map<String, Mapper.TypeParser> mappers = registerBuiltInMappers();
    Map<String, MetadataFieldMapper.TypeParser> metadataMappers = registerBuiltInMetadataMappers();
    MapperRegistry mapperRegistry = new MapperRegistry(mappers, metadataMappers);
    MapperService mapperService = new MapperService(new Index("test"),
            forcedSettings,
            newAnalysisService(forcedSettings),
            similarityLookupService,
            null,
            mapperRegistry);
    return new DocumentMapperParser(
            forcedSettings,
            mapperService,
            newAnalysisService(forcedSettings),
            similarityLookupService,
            null,
            mapperRegistry);
}
 
开发者ID:jprante,项目名称:elasticsearch-analysis-opennlp,代码行数:24,代码来源:MapperTestUtils.java

示例7: setupMapperParser

import org.elasticsearch.index.mapper.DocumentMapperParser; //导入依赖的package包/类
@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));
}
 
开发者ID:spinscale,项目名称:elasticsearch-opennlp-plugin,代码行数:23,代码来源:OpenNlpMappingTest.java

示例8: testSimilarityDefaultBackCompat

import org.elasticsearch.index.mapper.DocumentMapperParser; //导入依赖的package包/类
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]"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:SimilarityTests.java

示例9: testIndexNotConfigurable

import org.elasticsearch.index.mapper.DocumentMapperParser; //导入依赖的package包/类
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());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:IndexFieldMapperTests.java

示例10: testTypeLevel

import org.elasticsearch.index.mapper.DocumentMapperParser; //导入依赖的package包/类
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"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:DocumentMapperParserTests.java

示例11: testFieldNameWithDots

import org.elasticsearch.index.mapper.DocumentMapperParser; //导入依赖的package包/类
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"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:DocumentMapperParserTests.java

示例12: testFieldNameWithDeepDots

import org.elasticsearch.index.mapper.DocumentMapperParser; //导入依赖的package包/类
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"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:DocumentMapperParserTests.java

示例13: testFieldNameWithDotsConflict

import org.elasticsearch.index.mapper.DocumentMapperParser; //导入依赖的package包/类
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"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:DocumentMapperParserTests.java

示例14: testMergeObjectDynamic

import org.elasticsearch.index.mapper.DocumentMapperParser; //导入依赖的package包/类
public void testMergeObjectDynamic() throws Exception {
    DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
    String objectMapping = XContentFactory.jsonBuilder().startObject().startObject("type1").endObject().endObject().string();
    DocumentMapper mapper = parser.parse("type1", new CompressedXContent(objectMapping));
    assertNull(mapper.root().dynamic());

    String withDynamicMapping = XContentFactory.jsonBuilder().startObject().startObject("type1").field("dynamic", "false").endObject().endObject().string();
    DocumentMapper withDynamicMapper = parser.parse("type1", new CompressedXContent(withDynamicMapping));
    assertThat(withDynamicMapper.root().dynamic(), equalTo(ObjectMapper.Dynamic.FALSE));

    DocumentMapper merged = mapper.merge(withDynamicMapper.mapping(), false);
    assertThat(merged.root().dynamic(), equalTo(ObjectMapper.Dynamic.FALSE));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:DocumentMapperMergeTests.java

示例15: testObjectFieldNotAllowed

import org.elasticsearch.index.mapper.DocumentMapperParser; //导入依赖的package包/类
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"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:MultiFieldTests.java


注:本文中的org.elasticsearch.index.mapper.DocumentMapperParser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。