Search in sources :

Example 1 with MapperParsingException

use of org.opensearch.index.mapper.MapperParsingException in project OpenSearch by opensearch-project.

the class PercolatorFieldMapperTests method testAllowNoAdditionalSettings.

public void testAllowNoAdditionalSettings() throws Exception {
    addQueryFieldMappings();
    IndexService indexService = createIndex("test1", Settings.EMPTY);
    MapperService mapperService = indexService.mapperService();
    String percolatorMapper = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("doc").startObject("properties").startObject(fieldName).field("type", "percolator").field("index", "no").endObject().endObject().endObject().endObject());
    MapperParsingException e = expectThrows(MapperParsingException.class, () -> mapperService.merge("doc", new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE));
    assertThat(e.getMessage(), containsString("Mapping definition for [" + fieldName + "] has unsupported parameters:  [index : no]"));
}
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) MapperService(org.opensearch.index.mapper.MapperService)

Example 2 with MapperParsingException

use of org.opensearch.index.mapper.MapperParsingException in project OpenSearch by opensearch-project.

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 = "doc";
    String percolatorMapper = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject(typeName).startObject("properties").startObject("object_field").field("type", "object").startObject("properties").startObject("query_field").field("type", "percolator").endObject().endObject().endObject().endObject().endObject().endObject());
    mapperService.merge(typeName, new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE);
    QueryBuilder queryBuilder = matchQuery("field", "value");
    ParsedDocument doc = mapperService.documentMapper(typeName).parse(new SourceToParse("test", typeName, "1", BytesReference.bytes(jsonBuilder().startObject().startObject("object_field").field("query_field", queryBuilder).endObject().endObject()), XContentType.JSON));
    // also includes all other meta fields
    assertThat(doc.rootDoc().getFields().size(), equalTo(12));
    IndexableField queryBuilderField = doc.rootDoc().getField("object_field.query_field.query_builder_field");
    assertTrue(queryBuilderField.fieldType().omitNorms());
    IndexableField extractionResultField = doc.rootDoc().getField("object_field.query_field.extraction_result");
    assertTrue(extractionResultField.fieldType().omitNorms());
    BytesRef queryBuilderAsBytes = queryBuilderField.binaryValue();
    assertQueryBuilder(queryBuilderAsBytes, queryBuilder);
    doc = mapperService.documentMapper(typeName).parse(new SourceToParse("test", typeName, "1", BytesReference.bytes(jsonBuilder().startObject().startArray("object_field").startObject().field("query_field", queryBuilder).endObject().endArray().endObject()), XContentType.JSON));
    // also includes all other meta fields
    assertThat(doc.rootDoc().getFields().size(), equalTo(12));
    queryBuilderAsBytes = doc.rootDoc().getField("object_field.query_field.query_builder_field").binaryValue();
    assertQueryBuilder(queryBuilderAsBytes, queryBuilder);
    MapperParsingException e = expectThrows(MapperParsingException.class, () -> {
        mapperService.documentMapper(typeName).parse(new SourceToParse("test", typeName, "1", BytesReference.bytes(jsonBuilder().startObject().startArray("object_field").startObject().field("query_field", queryBuilder).endObject().startObject().field("query_field", queryBuilder).endObject().endArray().endObject()), XContentType.JSON));
    });
    assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
    assertThat(e.getCause().getMessage(), equalTo("a document can only contain one percolator query"));
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) MapperParsingException(org.opensearch.index.mapper.MapperParsingException) ParsedDocument(org.opensearch.index.mapper.ParsedDocument) CompressedXContent(org.opensearch.common.compress.CompressedXContent) SourceToParse(org.opensearch.index.mapper.SourceToParse) Matchers.containsString(org.hamcrest.Matchers.containsString) BoostingQueryBuilder(org.opensearch.index.query.BoostingQueryBuilder) BoolQueryBuilder(org.opensearch.index.query.BoolQueryBuilder) HasChildQueryBuilder(org.opensearch.join.query.HasChildQueryBuilder) ConstantScoreQueryBuilder(org.opensearch.index.query.ConstantScoreQueryBuilder) FunctionScoreQueryBuilder(org.opensearch.index.query.functionscore.FunctionScoreQueryBuilder) QueryBuilder(org.opensearch.index.query.QueryBuilder) ScriptQueryBuilder(org.opensearch.index.query.ScriptQueryBuilder) DisMaxQueryBuilder(org.opensearch.index.query.DisMaxQueryBuilder) RangeQueryBuilder(org.opensearch.index.query.RangeQueryBuilder) HasParentQueryBuilder(org.opensearch.join.query.HasParentQueryBuilder) MatchAllQueryBuilder(org.opensearch.index.query.MatchAllQueryBuilder) BytesRef(org.apache.lucene.util.BytesRef)

Example 3 with MapperParsingException

use of org.opensearch.index.mapper.MapperParsingException in project OpenSearch by opensearch-project.

the class PercolatorFieldMapperTests method testPercolatorFieldMapper_noQuery.

public void testPercolatorFieldMapper_noQuery() throws Exception {
    addQueryFieldMappings();
    ParsedDocument doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON));
    assertThat(doc.rootDoc().getFields(fieldType.queryBuilderField.name()).length, equalTo(0));
    try {
        mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().nullField(fieldName).endObject()), XContentType.JSON));
    } catch (MapperParsingException e) {
        assertThat(e.getDetailedMessage(), containsString("query malformed, must start with start_object"));
    }
}
Also used : MapperParsingException(org.opensearch.index.mapper.MapperParsingException) ParsedDocument(org.opensearch.index.mapper.ParsedDocument) SourceToParse(org.opensearch.index.mapper.SourceToParse)

Example 4 with MapperParsingException

use of org.opensearch.index.mapper.MapperParsingException in project OpenSearch by opensearch-project.

the class CompletionSuggestSearchIT method testThatWeightMustNotBeANonNumberString.

public void testThatWeightMustNotBeANonNumberString() throws Exception {
    createIndexAndMapping(completionMappingBuilder);
    MapperParsingException e = expectThrows(MapperParsingException.class, () -> client().prepareIndex(INDEX).setId("1").setSource(jsonBuilder().startObject().startObject(FIELD).startArray("input").value("sth").endArray().field("weight", "thisIsNotValid").endObject().endObject()).get());
    assertThat(e.toString(), containsString("thisIsNotValid"));
}
Also used : MapperParsingException(org.opensearch.index.mapper.MapperParsingException)

Example 5 with MapperParsingException

use of org.opensearch.index.mapper.MapperParsingException in project OpenSearch by opensearch-project.

the class CompletionSuggestSearchIT method testThatWeightMustBeAnInteger.

public void testThatWeightMustBeAnInteger() throws Exception {
    createIndexAndMapping(completionMappingBuilder);
    MapperParsingException e = expectThrows(MapperParsingException.class, () -> client().prepareIndex(INDEX).setId("1").setSource(jsonBuilder().startObject().startObject(FIELD).startArray("input").value("sth").endArray().field("weight", 2.5).endObject().endObject()).get());
    assertThat(e.toString(), containsString("2.5"));
}
Also used : MapperParsingException(org.opensearch.index.mapper.MapperParsingException)

Aggregations

MapperParsingException (org.opensearch.index.mapper.MapperParsingException)22 Matchers.containsString (org.hamcrest.Matchers.containsString)9 CompressedXContent (org.opensearch.common.compress.CompressedXContent)5 IOException (java.io.IOException)4 IndexService (org.opensearch.index.IndexService)4 SourceToParse (org.opensearch.index.mapper.SourceToParse)4 Map (java.util.Map)3 UncheckedIOException (java.io.UncheckedIOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)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