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());
}
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]"));
}
}
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]"));
}
}
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"));
}
}
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));
}
}
Aggregations