本文整理汇总了Java中org.elasticsearch.index.mapper.MapperParsingException类的典型用法代码示例。如果您正苦于以下问题:Java MapperParsingException类的具体用法?Java MapperParsingException怎么用?Java MapperParsingException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MapperParsingException类属于org.elasticsearch.index.mapper包,在下文中一共展示了MapperParsingException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import org.elasticsearch.index.mapper.MapperParsingException; //导入依赖的package包/类
@Override
public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
if (parserContext.indexVersionCreated().before(Version.V_1_3_0)) {
throw new IllegalArgumentException("type="+CONTENT_TYPE+" is not supported on indices created before version 1.3.0. Is your cluster running multiple datanode versions?");
}
Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
if (parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) {
parseField(builder, builder.name, node, parserContext);
}
for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
Map.Entry<String, Object> entry = iterator.next();
String fieldName = Strings.toUnderscoreCase(entry.getKey());
Object fieldNode = entry.getValue();
if (fieldName.equals("enabled")) {
builder.enabled(nodeBooleanValue(fieldNode));
iterator.remove();
}
}
return builder;
}
示例2: testBrokenMapping
import org.elasticsearch.index.mapper.MapperParsingException; //导入依赖的package包/类
public void testBrokenMapping() throws Exception {
// clean all templates setup by the framework.
client().admin().indices().prepareDeleteTemplate("*").get();
// check get all templates on an empty index.
GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates().get();
assertThat(response.getIndexTemplates(), empty());
MapperParsingException e = expectThrows( MapperParsingException.class,
() -> client().admin().indices().preparePutTemplate("template_1")
.setPatterns(Collections.singletonList("te*"))
.addMapping("type1", "{\"foo\": \"abcde\"}", XContentType.JSON)
.get());
assertThat(e.getMessage(), containsString("Failed to parse mapping "));
response = client().admin().indices().prepareGetTemplates().get();
assertThat(response.getIndexTemplates(), hasSize(0));
}
示例3: testThatWeightAsStringMustBeInt
import org.elasticsearch.index.mapper.MapperParsingException; //导入依赖的package包/类
public void testThatWeightAsStringMustBeInt() throws Exception {
createIndexAndMapping(completionMappingBuilder);
String weight = String.valueOf(Long.MAX_VALUE - 4);
try {
client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder()
.startObject().startObject(FIELD)
.startArray("input").value("testing").endArray()
.field("weight", weight)
.endObject().endObject()
).get();
fail("Indexing with weight string representing value > Int.MAX_VALUE was successful, but should not be");
} catch (MapperParsingException e) {
assertThat(e.toString(), containsString(weight));
}
}
示例4: testReservedChars
import org.elasticsearch.index.mapper.MapperParsingException; //导入依赖的package包/类
public void testReservedChars() throws IOException {
assertAcked(client().admin().indices().prepareCreate(INDEX).addMapping(TYPE, jsonBuilder().startObject()
.startObject(TYPE).startObject("properties")
.startObject(FIELD)
.field("type", "completion")
.endObject()
.endObject().endObject()
.endObject()).get());
// can cause stack overflow without the default max_input_length
String string = "foo" + (char) 0x00 + "bar";
try {
client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder()
.startObject().startObject(FIELD)
.startArray("input").value(string).endArray()
.field("output", "foobar")
.endObject().endObject()
).get();
fail("Expected MapperParsingException");
} catch (MapperParsingException e) {
assertThat(e.getMessage(), containsString("failed to parse"));
}
}
示例5: testFieldsArrayMultiFieldsShouldThrowException
import org.elasticsearch.index.mapper.MapperParsingException; //导入依赖的package包/类
public void testFieldsArrayMultiFieldsShouldThrowException() throws Exception {
String mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("tweet")
.startObject("properties")
.startObject("name")
.field("type", "text")
.startArray("fields")
.startObject().field("test", "string").endObject()
.startObject().field("test2", "string").endObject()
.endArray()
.endObject()
.endObject()
.endObject()
.endObject()
.string();
try {
createIndex("test").mapperService().documentMapperParser().parse("tweet", new CompressedXContent(mapping));
fail("Expected MapperParsingException");
} catch(MapperParsingException e) {
assertThat(e.getMessage(), containsString("expected map for property [fields]"));
assertThat(e.getMessage(), containsString("but got a class java.util.ArrayList"));
}
}
示例6: testFieldsWithFilledArrayShouldThrowException
import org.elasticsearch.index.mapper.MapperParsingException; //导入依赖的package包/类
public void testFieldsWithFilledArrayShouldThrowException() throws Exception {
String mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("tweet")
.startObject("properties")
.startArray("fields")
.startObject().field("test", "string").endObject()
.startObject().field("test2", "string").endObject()
.endArray()
.endObject()
.endObject()
.endObject()
.string();
try {
createIndex("test").mapperService().documentMapperParser().parse("tweet", new CompressedXContent(mapping));
fail("Expected MapperParsingException");
} catch (MapperParsingException e) {
assertThat(e.getMessage(), containsString("Expected map for property [fields]"));
}
}
示例7: testNullNullValue
import org.elasticsearch.index.mapper.MapperParsingException; //导入依赖的package包/类
public void testNullNullValue() throws Exception {
IndexService indexService = createIndex("test", Settings.builder().build());
String[] typesToTest = {"integer", "long", "double", "float", "short", "date", "ip", "keyword", "boolean", "byte"};
for (String type : typesToTest) {
String mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("type")
.startObject("properties")
.startObject("numeric")
.field("type", type)
.field("null_value", (String) null)
.endObject()
.endObject()
.endObject()
.endObject().string();
try {
indexService.mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
fail("Test should have failed because [null_value] was null.");
} catch (MapperParsingException e) {
assertThat(e.getMessage(), equalTo("Property [null_value] cannot be null."));
}
}
}
示例8: testMultiFieldWithDot
import org.elasticsearch.index.mapper.MapperParsingException; //导入依赖的package包/类
public void testMultiFieldWithDot() throws IOException {
XContentBuilder mapping = jsonBuilder();
mapping.startObject()
.startObject("my_type")
.startObject("properties")
.startObject("city")
.field("type", "text")
.startObject("fields")
.startObject("raw.foo")
.field("type", "text")
.field("index", "not_analyzed")
.endObject()
.endObject()
.endObject()
.endObject()
.endObject()
.endObject();
MapperService mapperService = createIndex("test").mapperService();
try {
mapperService.documentMapperParser().parse("my_type", new CompressedXContent(mapping.string()));
fail("this should throw an exception because one field contains a dot");
} catch (MapperParsingException e) {
assertThat(e.getMessage(), equalTo("Field name [raw.foo] which is a multi field of [city] cannot contain '.'"));
}
}
示例9: testFieldTypeToTermVectorString
import org.elasticsearch.index.mapper.MapperParsingException; //导入依赖的package包/类
public void testFieldTypeToTermVectorString() throws Exception {
FieldType ft = new FieldType();
ft.setStoreTermVectorOffsets(false);
ft.setStoreTermVectorPayloads(true);
ft.setStoreTermVectors(true);
ft.setStoreTermVectorPositions(true);
String ftOpts = FieldMapper.termVectorOptionsToString(ft);
assertThat("with_positions_payloads", equalTo(ftOpts));
AllFieldMapper.Builder builder = new AllFieldMapper.Builder(null);
boolean exceptiontrown = false;
try {
TypeParsers.parseTermVector("", ftOpts, builder);
} catch (MapperParsingException e) {
exceptiontrown = true;
}
assertThat("TypeParsers.parseTermVector should accept string with_positions_payloads but does not.", exceptiontrown, equalTo(false));
}
示例10: parse
import org.elasticsearch.index.mapper.MapperParsingException; //导入依赖的package包/类
@Override
public Mapper.Builder<?, ?> parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
Builder builder = new Builder(name);
// tweaking these settings is no longer allowed, the entire purpose of murmur3 fields is to store a hash
if (node.get("doc_values") != null) {
throw new MapperParsingException("Setting [doc_values] cannot be modified for field [" + name + "]");
}
if (node.get("index") != null) {
throw new MapperParsingException("Setting [index] cannot be modified for field [" + name + "]");
}
if (parserContext.indexVersionCreated().before(Version.V_5_0_0_alpha2)) {
node.remove("precision_step");
}
TypeParsers.parseField(builder, name, node, parserContext);
return builder;
}
示例11: parse
import org.elasticsearch.index.mapper.MapperParsingException; //导入依赖的package包/类
@Override
public MetadataFieldMapper.Builder<?, ?> parse(String name, Map<String, Object> node,
ParserContext parserContext) throws MapperParsingException {
Builder builder = new Builder(parserContext.mapperService().fullName(NAME),
parserContext.indexVersionCreated());
for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
Map.Entry<String, Object> entry = iterator.next();
String fieldName = entry.getKey();
Object fieldNode = entry.getValue();
if (fieldName.equals("enabled")) {
boolean enabled = TypeParsers.nodeBooleanValue(name, "enabled", fieldNode, parserContext);
builder.enabled(enabled ? EnabledAttributeMapper.ENABLED : EnabledAttributeMapper.DISABLED);
iterator.remove();
}
}
return builder;
}
示例12: parse
import org.elasticsearch.index.mapper.MapperParsingException; //导入依赖的package包/类
@Override
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
IpFieldMapper.Builder builder = ipField(name);
parseNumberField(builder, name, node, parserContext);
for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
Map.Entry<String, Object> entry = iterator.next();
String propName = Strings.toUnderscoreCase(entry.getKey());
Object propNode = entry.getValue();
if (propName.equals("null_value")) {
if (propNode == null) {
throw new MapperParsingException("Property [null_value] cannot be null.");
}
builder.nullValue(propNode.toString());
iterator.remove();
}
}
return builder;
}
示例13: parse
import org.elasticsearch.index.mapper.MapperParsingException; //导入依赖的package包/类
@Override
public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
Builder builder = new Builder();
for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
Map.Entry<String, Object> entry = iterator.next();
String fieldName = Strings.toUnderscoreCase(entry.getKey());
Object fieldNode = entry.getValue();
if (fieldName.equals("enabled")) {
EnabledAttributeMapper enabledState = nodeBooleanValue(fieldNode) ? EnabledAttributeMapper.ENABLED : EnabledAttributeMapper.DISABLED;
builder.enabled(enabledState);
iterator.remove();
} else if (fieldName.equals("default")) {
TimeValue ttlTimeValue = nodeTimeValue(fieldNode, null);
if (ttlTimeValue != null) {
builder.defaultTTL(ttlTimeValue.millis());
}
iterator.remove();
}
}
return builder;
}
示例14: parse
import org.elasticsearch.index.mapper.MapperParsingException; //导入依赖的package包/类
@Override
public MetadataFieldMapper.Builder<?, ?> parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
Builder builder = new Builder();
for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
Map.Entry<String, Object> entry = iterator.next();
String fieldName = Strings.toUnderscoreCase(entry.getKey());
if (fieldName.equals("doc_values_format") && parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) {
// ignore in 1.x, reject in 2.x
iterator.remove();
} else if (fieldName.equals("path")) {
builder.path(entry.getValue().toString());
iterator.remove();
} else if (fieldName.equals("version_type")) {
builder.versionType(entry.getValue().toString());
iterator.remove();
}
}
return builder;
}
示例15: parse
import org.elasticsearch.index.mapper.MapperParsingException; //导入依赖的package包/类
@Override
public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
if (parserContext.indexVersionCreated().onOrAfter(Version.V_2_0_0_beta1)) {
return builder;
}
parseField(builder, builder.name, node, parserContext);
for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
Map.Entry<String, Object> entry = iterator.next();
String fieldName = Strings.toUnderscoreCase(entry.getKey());
Object fieldNode = entry.getValue();
if (fieldName.equals("enabled")) {
EnabledAttributeMapper mapper = nodeBooleanValue(fieldNode) ? EnabledAttributeMapper.ENABLED : EnabledAttributeMapper.DISABLED;
builder.enabled(mapper);
iterator.remove();
}
}
return builder;
}