use of org.elasticsearch.index.mapper.MapperParsingException in project elasticsearch by elastic.
the class PercolatorFieldMapperTests method testPercolatorFieldMapper_noQuery.
public void testPercolatorFieldMapper_noQuery() throws Exception {
addQueryMapping();
ParsedDocument doc = mapperService.documentMapper(typeName).parse("test", typeName, "1", XContentFactory.jsonBuilder().startObject().endObject().bytes());
assertThat(doc.rootDoc().getFields(fieldType.queryBuilderField.name()).length, equalTo(0));
try {
mapperService.documentMapper(typeName).parse("test", typeName, "1", XContentFactory.jsonBuilder().startObject().nullField(fieldName).endObject().bytes());
} catch (MapperParsingException e) {
assertThat(e.getDetailedMessage(), containsString("query malformed, must start with start_object"));
}
}
use of org.elasticsearch.index.mapper.MapperParsingException in project elasticsearch by elastic.
the class PercolatorQuerySearchIT method testWithMultiplePercolatorFields.
public void testWithMultiplePercolatorFields() throws Exception {
String queryFieldName = randomAsciiOfLength(8);
createIndex("test1", client().admin().indices().prepareCreate("test1").addMapping("doc_type", "field", "type=keyword").addMapping("query_type", queryFieldName, "type=percolator"));
createIndex("test2", client().admin().indices().prepareCreate("test2").addMapping("doc_type", "field", "type=keyword").addMapping("query_type", jsonBuilder().startObject().startObject("query_type").startObject("properties").startObject("object_field").field("type", "object").startObject("properties").startObject(queryFieldName).field("type", "percolator").endObject().endObject().endObject().endObject().endObject().endObject()));
// Acceptable:
client().prepareIndex("test1", "query_type", "1").setSource(jsonBuilder().startObject().field(queryFieldName, matchQuery("field", "value")).endObject()).get();
client().prepareIndex("test2", "query_type", "1").setSource(jsonBuilder().startObject().startObject("object_field").field(queryFieldName, matchQuery("field", "value")).endObject().endObject()).get();
client().admin().indices().prepareRefresh().get();
BytesReference source = jsonBuilder().startObject().field("field", "value").endObject().bytes();
SearchResponse response = client().prepareSearch().setQuery(new PercolateQueryBuilder(queryFieldName, "doc_type", source, XContentType.JSON)).setIndices("test1").get();
assertHitCount(response, 1);
assertThat(response.getHits().getAt(0).getId(), equalTo("1"));
assertThat(response.getHits().getAt(0).getType(), equalTo("query_type"));
assertThat(response.getHits().getAt(0).getIndex(), equalTo("test1"));
response = client().prepareSearch().setQuery(new PercolateQueryBuilder("object_field." + queryFieldName, "doc_type", source, XContentType.JSON)).setIndices("test2").get();
assertHitCount(response, 1);
assertThat(response.getHits().getAt(0).getId(), equalTo("1"));
assertThat(response.getHits().getAt(0).getType(), equalTo("query_type"));
assertThat(response.getHits().getAt(0).getIndex(), equalTo("test2"));
// Unacceptable:
MapperParsingException e = expectThrows(MapperParsingException.class, () -> {
client().prepareIndex("test2", "query_type", "1").setSource(jsonBuilder().startObject().startArray("object_field").startObject().field(queryFieldName, matchQuery("field", "value")).endObject().startObject().field(queryFieldName, matchQuery("field", "value")).endObject().endArray().endObject()).get();
});
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 NullValueTests method testNullNullValue.
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."));
}
}
}
use of org.elasticsearch.index.mapper.MapperParsingException in project elasticsearch by elastic.
the class RoutingFieldMapperTests method testIncludeInObjectNotAllowed.
public void testIncludeInObjectNotAllowed() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
try {
docMapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject().field("_routing", "foo").endObject().bytes());
fail("Expected failure to parse metadata field");
} catch (MapperParsingException e) {
assertTrue(e.getMessage(), e.getMessage().contains("Field [_routing] is a metadata field and cannot be added inside a document"));
}
}
use of org.elasticsearch.index.mapper.MapperParsingException in project elasticsearch by elastic.
the class ObjectMapperTests method testFieldsWithFilledArrayShouldThrowException.
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]"));
}
}
Aggregations