Search in sources :

Example 16 with MapperParsingException

use of org.elasticsearch.index.mapper.MapperParsingException in project elasticsearch by elastic.

the class GeoShapeQueryTests method testPointsOnly.

public void testPointsOnly() throws Exception {
    String mapping = 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().string();
    client().admin().indices().prepareCreate("geo_points_only").addMapping("type1", mapping, XContentType.JSON).execute().actionGet();
    ensureGreen();
    ShapeBuilder shape = RandomShapeGenerator.createShape(random());
    try {
        client().prepareIndex("geo_points_only", "type1", "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").setTypes("type1").setQuery(geoIntersectionQuery("location", shape)).execute().actionGet();
    assertEquals(1, response.getHits().getTotalHits());
}
Also used : ShapeBuilder(org.elasticsearch.common.geo.builders.ShapeBuilder) MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) Matchers.containsString(org.hamcrest.Matchers.containsString) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 17 with MapperParsingException

use of org.elasticsearch.index.mapper.MapperParsingException in project elasticsearch by elastic.

the class SimilarityTests method testSimilarityDefaultBackCompat.

public void testSimilarityDefaultBackCompat() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field1").field("similarity", "default").field("type", "text").endObject().endObject().endObject().endObject().string();
    Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_2_2_0)).build();
    DocumentMapperParser parser = createIndex("test_v2.x", settings).mapperService().documentMapperParser();
    DocumentMapper documentMapper = parser.parse("type", new CompressedXContent(mapping));
    assertThat(documentMapper.mappers().getMapper("field1").fieldType().similarity(), instanceOf(ClassicSimilarityProvider.class));
    assertThat(documentMapper.mappers().getMapper("field1").fieldType().similarity().name(), equalTo("classic"));
    parser = createIndex("test_v3.x").mapperService().documentMapperParser();
    try {
        parser.parse("type", new CompressedXContent(mapping));
        fail("Expected MappingParsingException");
    } catch (MapperParsingException e) {
        assertThat(e.getMessage(), equalTo("Unknown Similarity type [default] for field [field1]"));
    }
}
Also used : MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) DocumentMapperParser(org.elasticsearch.index.mapper.DocumentMapperParser) Settings(org.elasticsearch.common.settings.Settings)

Example 18 with MapperParsingException

use of org.elasticsearch.index.mapper.MapperParsingException in project elasticsearch by elastic.

the class SimilarityTests method testResolveSimilaritiesFromMapping_Unknown.

public void testResolveSimilaritiesFromMapping_Unknown() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field1").field("type", "text").field("similarity", "unknown_similarity").endObject().endObject().endObject().endObject().string();
    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.elasticsearch.index.mapper.MapperParsingException) IndexService(org.elasticsearch.index.IndexService) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent)

Example 19 with MapperParsingException

use of org.elasticsearch.index.mapper.MapperParsingException in project elasticsearch by elastic.

the class CompletionSuggestSearchIT method testReservedChars.

// see #3648
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"));
    }
}
Also used : MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 20 with MapperParsingException

use of org.elasticsearch.index.mapper.MapperParsingException in project elasticsearch by elastic.

the class CompletionSuggestSearchIT method testThatWeightAsStringMustBeInt.

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));
    }
}
Also used : MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

MapperParsingException (org.elasticsearch.index.mapper.MapperParsingException)35 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)16 Matchers.containsString (org.hamcrest.Matchers.containsString)11 IndexService (org.elasticsearch.index.IndexService)7 Settings (org.elasticsearch.common.settings.Settings)5 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)5 Index (org.elasticsearch.index.Index)4 MapperService (org.elasticsearch.index.mapper.MapperService)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 DocumentMapperParser (org.elasticsearch.index.mapper.DocumentMapperParser)3 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 GetIndexTemplatesResponse (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)2 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)2 ValidationException (org.elasticsearch.common.ValidationException)2 IndexScopedSettings (org.elasticsearch.common.settings.IndexScopedSettings)2 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)2