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