use of org.opensearch.index.mapper.MapperParsingException in project OpenSearch by opensearch-project.
the class ParentJoinFieldMapperTests method testInvalidJoinFieldInsideObject.
public void testInvalidJoinFieldInsideObject() throws Exception {
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("properties").startObject("object").startObject("properties").startObject("join_field").field("type", "join").startObject("relations").field("parent", "child").endObject().endObject().endObject().endObject().endObject().endObject());
IndexService indexService = createIndex("test");
MapperParsingException exc = expectThrows(MapperParsingException.class, () -> indexService.mapperService().merge("type", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE));
assertThat(exc.getRootCause().getMessage(), containsString("join field [object.join_field] cannot be added inside an object or in a multi-field"));
}
use of org.opensearch.index.mapper.MapperParsingException in project OpenSearch by opensearch-project.
the class ParentJoinFieldMapperTests method testInvalidJoinFieldInsideMultiFields.
public void testInvalidJoinFieldInsideMultiFields() throws Exception {
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("properties").startObject("number").field("type", "integer").startObject("fields").startObject("join_field").field("type", "join").startObject("relations").field("parent", "child").endObject().endObject().endObject().endObject().endObject().endObject());
IndexService indexService = createIndex("test");
MapperParsingException exc = expectThrows(MapperParsingException.class, () -> indexService.mapperService().merge("type", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE));
assertThat(exc.getRootCause().getMessage(), containsString("join field [number.join_field] cannot be added inside an object or in a multi-field"));
}
use of org.opensearch.index.mapper.MapperParsingException in project OpenSearch by opensearch-project.
the class IndexActionIT method testDocumentWithBlankFieldName.
public void testDocumentWithBlankFieldName() {
MapperParsingException e = expectThrows(MapperParsingException.class, () -> {
client().prepareIndex("test").setId("1").setSource("", "value1_2").execute().actionGet();
});
assertThat(e.getMessage(), containsString("failed to parse"));
assertThat(e.getRootCause().getMessage(), containsString("field name cannot be an empty string"));
}
use of org.opensearch.index.mapper.MapperParsingException in project OpenSearch by opensearch-project.
the class GeoShapeQueryTests method testPointsOnly.
public void testPointsOnly() throws Exception {
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("location").field("type", "geo_shape").field("tree", randomBoolean() ? "quadtree" : "geohash").field("tree_levels", "6").field("distance_error_pct", "0.01").field("points_only", true).endObject().endObject().endObject().endObject());
client().admin().indices().prepareCreate("geo_points_only").addMapping("type1", mapping, XContentType.JSON).get();
ensureGreen();
ShapeBuilder shape = RandomShapeGenerator.createShape(random());
try {
client().prepareIndex("geo_points_only").setId("1").setSource(jsonBuilder().startObject().field("location", shape).endObject()).setRefreshPolicy(IMMEDIATE).get();
} catch (MapperParsingException e) {
// RandomShapeGenerator created something other than a POINT type, verify the correct exception is thrown
assertThat(e.getCause().getMessage(), containsString("is configured for points only"));
return;
}
// test that point was inserted
SearchResponse response = client().prepareSearch("geo_points_only").setQuery(geoIntersectionQuery("location", shape)).get();
assertHitCount(response, 1);
}
use of org.opensearch.index.mapper.MapperParsingException in project OpenSearch by opensearch-project.
the class SimilarityTests method testResolveSimilaritiesFromMapping_Unknown.
public void testResolveSimilaritiesFromMapping_Unknown() throws IOException {
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field1").field("type", "text").field("similarity", "unknown_similarity").endObject().endObject().endObject().endObject());
IndexService indexService = createIndex("foo");
try {
indexService.mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
fail("Expected MappingParsingException");
} catch (MapperParsingException e) {
assertThat(e.getMessage(), equalTo("Unknown Similarity type [unknown_similarity] for field [field1]"));
}
}
Aggregations