use of org.elasticsearch.index.mapper.MapperParsingException in project elasticsearch by elastic.
the class CompletionSuggestSearchIT method testIndexingUnrelatedNullValue.
// see issue #6399
public void testIndexingUnrelatedNullValue() throws Exception {
String mapping = jsonBuilder().startObject().startObject(TYPE).startObject("properties").startObject(FIELD).field("type", "completion").endObject().endObject().endObject().endObject().string();
assertAcked(client().admin().indices().prepareCreate(INDEX).addMapping(TYPE, mapping, XContentType.JSON).get());
ensureGreen();
client().prepareIndex(INDEX, TYPE, "1").setSource(FIELD, "strings make me happy", FIELD + "_1", "nulls make me sad").setRefreshPolicy(IMMEDIATE).get();
try {
client().prepareIndex(INDEX, TYPE, "2").setSource(FIELD, null, FIELD + "_1", "nulls make me sad").get();
fail("Expected MapperParsingException for null value");
} catch (MapperParsingException e) {
// make sure that the exception has the name of the field causing the error
assertTrue(e.getDetailedMessage().contains(FIELD));
}
}
use of org.elasticsearch.index.mapper.MapperParsingException in project elasticsearch by elastic.
the class PercolatorFieldMapperTests method testPercolatorFieldMapperUnMappedField.
public void testPercolatorFieldMapperUnMappedField() throws Exception {
addQueryMapping();
MapperParsingException exception = expectThrows(MapperParsingException.class, () -> {
mapperService.documentMapper(typeName).parse("test", typeName, "1", XContentFactory.jsonBuilder().startObject().field(fieldName, termQuery("unmapped_field", "value")).endObject().bytes());
});
assertThat(exception.getCause(), instanceOf(QueryShardException.class));
assertThat(exception.getCause().getMessage(), equalTo("No field mapping can be found for the field with name [unmapped_field]"));
}
use of org.elasticsearch.index.mapper.MapperParsingException in project elasticsearch by elastic.
the class PercolatorFieldMapperTests method testVerifyRangeQueryWithNullBounds.
// https://github.com/elastic/elasticsearch/issues/22355
public void testVerifyRangeQueryWithNullBounds() throws Exception {
addQueryMapping();
MapperParsingException e = expectThrows(MapperParsingException.class, () -> {
mapperService.documentMapper(typeName).parse("test", typeName, "1", jsonBuilder().startObject().field(fieldName, rangeQuery("date_field").from("now").to(null)).endObject().bytes());
});
assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
e = expectThrows(MapperParsingException.class, () -> {
mapperService.documentMapper(typeName).parse("test", typeName, "1", jsonBuilder().startObject().field(fieldName, rangeQuery("date_field").from(null).to("now")).endObject().bytes());
});
assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
// No validation failures:
mapperService.documentMapper(typeName).parse("test", typeName, "1", jsonBuilder().startObject().field(fieldName, rangeQuery("date_field").from("2016-01-01").to(null)).endObject().bytes());
mapperService.documentMapper(typeName).parse("test", typeName, "1", jsonBuilder().startObject().field(fieldName, rangeQuery("date_field").from(null).to("2016-01-01")).endObject().bytes());
}
use of org.elasticsearch.index.mapper.MapperParsingException in project elasticsearch by elastic.
the class PercolatorFieldMapperTests method testNestedPercolatorField.
// percolator field can be nested under an object field, but only one query can be specified per document
public void testNestedPercolatorField() throws Exception {
String typeName = "another_type";
String percolatorMapper = XContentFactory.jsonBuilder().startObject().startObject(typeName).startObject("_field_names").field("enabled", false).endObject().startObject("properties").startObject("object_field").field("type", "object").startObject("properties").startObject("query_field").field("type", "percolator").endObject().endObject().endObject().endObject().endObject().endObject().string();
mapperService.merge(typeName, new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE, true);
QueryBuilder queryBuilder = matchQuery("field", "value");
ParsedDocument doc = mapperService.documentMapper(typeName).parse("test", typeName, "1", jsonBuilder().startObject().startObject("object_field").field("query_field", queryBuilder).endObject().endObject().bytes());
// also includes all other meta fields
assertThat(doc.rootDoc().getFields().size(), equalTo(11));
BytesRef queryBuilderAsBytes = doc.rootDoc().getField("object_field.query_field.query_builder_field").binaryValue();
assertQueryBuilder(queryBuilderAsBytes, queryBuilder);
doc = mapperService.documentMapper(typeName).parse("test", typeName, "1", jsonBuilder().startObject().startArray("object_field").startObject().field("query_field", queryBuilder).endObject().endArray().endObject().bytes());
// also includes all other meta fields
assertThat(doc.rootDoc().getFields().size(), equalTo(11));
queryBuilderAsBytes = doc.rootDoc().getField("object_field.query_field.query_builder_field").binaryValue();
assertQueryBuilder(queryBuilderAsBytes, queryBuilder);
MapperParsingException e = expectThrows(MapperParsingException.class, () -> {
mapperService.documentMapper(typeName).parse("test", typeName, "1", jsonBuilder().startObject().startArray("object_field").startObject().field("query_field", queryBuilder).endObject().startObject().field("query_field", queryBuilder).endObject().endArray().endObject().bytes());
});
assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
assertThat(e.getCause().getMessage(), equalTo("a document can only contain one percolator query"));
}
use of org.elasticsearch.index.mapper.MapperParsingException in project elasticsearch by elastic.
the class PercolatorFieldMapperTests method testAllowNoAdditionalSettings.
public void testAllowNoAdditionalSettings() throws Exception {
addQueryMapping();
IndexService indexService = createIndex("test1", Settings.EMPTY);
MapperService mapperService = indexService.mapperService();
String percolatorMapper = XContentFactory.jsonBuilder().startObject().startObject(typeName).startObject("properties").startObject(fieldName).field("type", "percolator").field("index", "no").endObject().endObject().endObject().endObject().string();
MapperParsingException e = expectThrows(MapperParsingException.class, () -> mapperService.merge(typeName, new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE, true));
assertThat(e.getMessage(), containsString("Mapping definition for [" + fieldName + "] has unsupported parameters: [index : no]"));
}
Aggregations