Search in sources :

Example 21 with MapperParsingException

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

the class CompletionSuggestSearchIT method testIndexingUnrelatedNullValue.

// see issue #6399
public void testIndexingUnrelatedNullValue() throws Exception {
    String mapping = jsonBuilder().startObject().startObject(TYPE).startObject("properties").startObject(FIELD).field("type", "completion").endObject().endObject().endObject().endObject().string();
    assertAcked(client().admin().indices().prepareCreate(INDEX).addMapping(TYPE, mapping, XContentType.JSON).get());
    ensureGreen();
    client().prepareIndex(INDEX, TYPE, "1").setSource(FIELD, "strings make me happy", FIELD + "_1", "nulls make me sad").setRefreshPolicy(IMMEDIATE).get();
    try {
        client().prepareIndex(INDEX, TYPE, "2").setSource(FIELD, null, FIELD + "_1", "nulls make me sad").get();
        fail("Expected MapperParsingException for null value");
    } catch (MapperParsingException e) {
        // make sure that the exception has the name of the field causing the error
        assertTrue(e.getDetailedMessage().contains(FIELD));
    }
}
Also used : MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 22 with MapperParsingException

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

the class PercolatorFieldMapperTests method testPercolatorFieldMapperUnMappedField.

public void testPercolatorFieldMapperUnMappedField() throws Exception {
    addQueryMapping();
    MapperParsingException exception = expectThrows(MapperParsingException.class, () -> {
        mapperService.documentMapper(typeName).parse("test", typeName, "1", XContentFactory.jsonBuilder().startObject().field(fieldName, termQuery("unmapped_field", "value")).endObject().bytes());
    });
    assertThat(exception.getCause(), instanceOf(QueryShardException.class));
    assertThat(exception.getCause().getMessage(), equalTo("No field mapping can be found for the field with name [unmapped_field]"));
}
Also used : MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) QueryShardException(org.elasticsearch.index.query.QueryShardException)

Example 23 with MapperParsingException

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

the class PercolatorFieldMapperTests method testVerifyRangeQueryWithNullBounds.

// https://github.com/elastic/elasticsearch/issues/22355
public void testVerifyRangeQueryWithNullBounds() throws Exception {
    addQueryMapping();
    MapperParsingException e = expectThrows(MapperParsingException.class, () -> {
        mapperService.documentMapper(typeName).parse("test", typeName, "1", jsonBuilder().startObject().field(fieldName, rangeQuery("date_field").from("now").to(null)).endObject().bytes());
    });
    assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
    e = expectThrows(MapperParsingException.class, () -> {
        mapperService.documentMapper(typeName).parse("test", typeName, "1", jsonBuilder().startObject().field(fieldName, rangeQuery("date_field").from(null).to("now")).endObject().bytes());
    });
    assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
    // No validation failures:
    mapperService.documentMapper(typeName).parse("test", typeName, "1", jsonBuilder().startObject().field(fieldName, rangeQuery("date_field").from("2016-01-01").to(null)).endObject().bytes());
    mapperService.documentMapper(typeName).parse("test", typeName, "1", jsonBuilder().startObject().field(fieldName, rangeQuery("date_field").from(null).to("2016-01-01")).endObject().bytes());
}
Also used : MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException)

Example 24 with MapperParsingException

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

the class PercolatorFieldMapperTests method testNestedPercolatorField.

// percolator field can be nested under an object field, but only one query can be specified per document
public void testNestedPercolatorField() throws Exception {
    String typeName = "another_type";
    String percolatorMapper = XContentFactory.jsonBuilder().startObject().startObject(typeName).startObject("_field_names").field("enabled", false).endObject().startObject("properties").startObject("object_field").field("type", "object").startObject("properties").startObject("query_field").field("type", "percolator").endObject().endObject().endObject().endObject().endObject().endObject().string();
    mapperService.merge(typeName, new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE, true);
    QueryBuilder queryBuilder = matchQuery("field", "value");
    ParsedDocument doc = mapperService.documentMapper(typeName).parse("test", typeName, "1", jsonBuilder().startObject().startObject("object_field").field("query_field", queryBuilder).endObject().endObject().bytes());
    // also includes all other meta fields
    assertThat(doc.rootDoc().getFields().size(), equalTo(11));
    BytesRef queryBuilderAsBytes = doc.rootDoc().getField("object_field.query_field.query_builder_field").binaryValue();
    assertQueryBuilder(queryBuilderAsBytes, queryBuilder);
    doc = mapperService.documentMapper(typeName).parse("test", typeName, "1", jsonBuilder().startObject().startArray("object_field").startObject().field("query_field", queryBuilder).endObject().endArray().endObject().bytes());
    // also includes all other meta fields
    assertThat(doc.rootDoc().getFields().size(), equalTo(11));
    queryBuilderAsBytes = doc.rootDoc().getField("object_field.query_field.query_builder_field").binaryValue();
    assertQueryBuilder(queryBuilderAsBytes, queryBuilder);
    MapperParsingException e = expectThrows(MapperParsingException.class, () -> {
        mapperService.documentMapper(typeName).parse("test", typeName, "1", jsonBuilder().startObject().startArray("object_field").startObject().field("query_field", queryBuilder).endObject().startObject().field("query_field", queryBuilder).endObject().endArray().endObject().bytes());
    });
    assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
    assertThat(e.getCause().getMessage(), equalTo("a document can only contain one percolator query"));
}
Also used : MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString) HasParentQueryBuilder(org.elasticsearch.index.query.HasParentQueryBuilder) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) MatchAllQueryBuilder(org.elasticsearch.index.query.MatchAllQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) ConstantScoreQueryBuilder(org.elasticsearch.index.query.ConstantScoreQueryBuilder) FunctionScoreQueryBuilder(org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoostingQueryBuilder(org.elasticsearch.index.query.BoostingQueryBuilder) HasChildQueryBuilder(org.elasticsearch.index.query.HasChildQueryBuilder) BytesRef(org.apache.lucene.util.BytesRef)

Example 25 with MapperParsingException

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

the class PercolatorFieldMapperTests method testAllowNoAdditionalSettings.

public void testAllowNoAdditionalSettings() throws Exception {
    addQueryMapping();
    IndexService indexService = createIndex("test1", Settings.EMPTY);
    MapperService mapperService = indexService.mapperService();
    String percolatorMapper = XContentFactory.jsonBuilder().startObject().startObject(typeName).startObject("properties").startObject(fieldName).field("type", "percolator").field("index", "no").endObject().endObject().endObject().endObject().string();
    MapperParsingException e = expectThrows(MapperParsingException.class, () -> mapperService.merge(typeName, new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE, true));
    assertThat(e.getMessage(), containsString("Mapping definition for [" + fieldName + "] has unsupported parameters:  [index : no]"));
}
Also used : MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) IndexService(org.elasticsearch.index.IndexService) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString) MapperService(org.elasticsearch.index.mapper.MapperService)

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