本文整理汇总了Java中org.elasticsearch.index.mapper.DocumentMapperParser.parse方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentMapperParser.parse方法的具体用法?Java DocumentMapperParser.parse怎么用?Java DocumentMapperParser.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.index.mapper.DocumentMapperParser
的用法示例。
在下文中一共展示了DocumentMapperParser.parse方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例2: 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());
}
示例3: 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"));
}
示例4: 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]"));
}
}
示例5: 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"));
}
示例6: 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"));
}
示例7: 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"));
}
示例8: 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));
}
示例9: 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"));
}
}
示例10: testNestedFieldNotAllowed
import org.elasticsearch.index.mapper.DocumentMapperParser; //导入方法依赖的package包/类
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"));
}
}
示例11: testRefFromID
import org.elasticsearch.index.mapper.DocumentMapperParser; //导入方法依赖的package包/类
@Test
public void testRefFromID() throws Exception {
String mapping = copyToStringFromClasspath("ref-mapping-from-id.json");
DocumentMapperParser mapperParser = newDocumentMapperParser("docs");
DocumentMapper docMapper = mapperParser.parse("docs", new CompressedXContent(mapping));
BytesReference json = jsonBuilder().startObject()
.field("title", "A title")
.field("authorID", "1")
.endObject().bytes();
ParseContext.Document doc = docMapper.parse("docs", "docs", "1", json).rootDoc();
assertEquals(1, doc.getFields("ref").length, 1);
assertEquals("John Doe", doc.getFields("ref")[0].stringValue());
}