Search in sources :

Example 6 with MapperParsingException

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"));
}
Also used : MapperParsingException(org.opensearch.index.mapper.MapperParsingException) IndexService(org.opensearch.index.IndexService) CompressedXContent(org.opensearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 7 with MapperParsingException

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"));
}
Also used : MapperParsingException(org.opensearch.index.mapper.MapperParsingException) IndexService(org.opensearch.index.IndexService) CompressedXContent(org.opensearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 8 with MapperParsingException

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"));
}
Also used : MapperParsingException(org.opensearch.index.mapper.MapperParsingException)

Example 9 with MapperParsingException

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);
}
Also used : ShapeBuilder(org.opensearch.common.geo.builders.ShapeBuilder) MapperParsingException(org.opensearch.index.mapper.MapperParsingException) Matchers.containsString(org.hamcrest.Matchers.containsString) OpenSearchAssertions.assertSearchResponse(org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse) SearchResponse(org.opensearch.action.search.SearchResponse)

Example 10 with MapperParsingException

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]"));
    }
}
Also used : MapperParsingException(org.opensearch.index.mapper.MapperParsingException) IndexService(org.opensearch.index.IndexService) CompressedXContent(org.opensearch.common.compress.CompressedXContent)

Aggregations

MapperParsingException (org.opensearch.index.mapper.MapperParsingException)24 Matchers.containsString (org.hamcrest.Matchers.containsString)9 Map (java.util.Map)5 CompressedXContent (org.opensearch.common.compress.CompressedXContent)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 IndexService (org.opensearch.index.IndexService)4 SourceToParse (org.opensearch.index.mapper.SourceToParse)4 UncheckedIOException (java.io.UncheckedIOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 GetIndexTemplatesResponse (org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse)2 ValidationException (org.opensearch.common.ValidationException)2 IndexScopedSettings (org.opensearch.common.settings.IndexScopedSettings)2 Settings (org.opensearch.common.settings.Settings)2 ParsedDocument (org.opensearch.index.mapper.ParsedDocument)2 IndexTemplateMissingException (org.opensearch.indices.IndexTemplateMissingException)2 InvalidIndexTemplateException (org.opensearch.indices.InvalidIndexTemplateException)2 Charset (java.nio.charset.Charset)1 FileVisitResult (java.nio.file.FileVisitResult)1