use of org.opensearch.index.mapper.DocumentMapper in project OpenSearch by opensearch-project.
the class CategoryContextMappingTests method testIndexingWithMixedTypeContextListHavingNULL.
public void testIndexingWithMixedTypeContextListHavingNULL() throws Exception {
String mapping = Strings.toString(jsonBuilder().startObject().startObject("properties").startObject("completion").field("type", "completion").startArray("contexts").startObject().field("name", "ctx").field("type", "category").endObject().endArray().endObject().endObject().endObject());
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
XContentBuilder builder = jsonBuilder().startObject().startObject("completion").array("input", "suggestion5", "suggestion6", "suggestion7").startObject("contexts").array("ctx", "ctx1", true, 100, null).endObject().field("weight", 5).endObject().endObject();
Exception e = expectThrows(MapperParsingException.class, () -> defaultMapper.parse(new SourceToParse("test", "1", BytesReference.bytes(builder), XContentType.JSON)));
assertEquals("context array must have string, number or boolean values, but was [VALUE_NULL]", e.getCause().getMessage());
}
use of org.opensearch.index.mapper.DocumentMapper in project OpenSearch by opensearch-project.
the class CategoryContextMappingTests method testIndexingWithSimpleNULLContexts.
public void testIndexingWithSimpleNULLContexts() throws Exception {
String mapping = Strings.toString(jsonBuilder().startObject().startObject("properties").startObject("completion").field("type", "completion").startArray("contexts").startObject().field("name", "ctx").field("type", "category").endObject().endArray().endObject().endObject().endObject());
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
XContentBuilder builder = jsonBuilder().startObject().startArray("completion").startObject().array("input", "suggestion5", "suggestion6", "suggestion7").startObject("contexts").nullField("ctx").endObject().field("weight", 5).endObject().endArray().endObject();
Exception e = expectThrows(MapperParsingException.class, () -> defaultMapper.parse(new SourceToParse("test", "1", BytesReference.bytes(builder), XContentType.JSON)));
assertEquals("contexts must be a string, number or boolean or a list of string, number or boolean, but was [VALUE_NULL]", e.getCause().getMessage());
}
use of org.opensearch.index.mapper.DocumentMapper in project OpenSearch by opensearch-project.
the class EngineTestCase method nestedParsedDocFactory.
public static CheckedBiFunction<String, Integer, ParsedDocument, IOException> nestedParsedDocFactory() throws Exception {
final MapperService mapperService = createMapperService();
final String nestedMapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("nested_field").field("type", "nested").endObject().endObject().endObject().endObject());
final DocumentMapper nestedMapper = mapperService.documentMapperParser().parse("type", new CompressedXContent(nestedMapping));
return (docId, nestedFieldValues) -> {
final XContentBuilder source = XContentFactory.jsonBuilder().startObject().field("field", "value");
if (nestedFieldValues > 0) {
XContentBuilder nestedField = source.startObject("nested_field");
for (int i = 0; i < nestedFieldValues; i++) {
nestedField.field("field-" + i, "value-" + i);
}
source.endObject();
}
source.endObject();
return nestedMapper.parse(new SourceToParse("test", docId, BytesReference.bytes(source), XContentType.JSON));
};
}
use of org.opensearch.index.mapper.DocumentMapper in project OpenSearch by opensearch-project.
the class CompositeAggregatorTests method mapperServiceMock.
@Override
protected MapperService mapperServiceMock() {
MapperService mapperService = mock(MapperService.class);
DocumentMapper mapper = mock(DocumentMapper.class);
when(mapper.typeText()).thenReturn(new Text("_doc"));
when(mapper.type()).thenReturn("_doc");
when(mapperService.documentMapper()).thenReturn(mapper);
return mapperService;
}
use of org.opensearch.index.mapper.DocumentMapper in project OpenSearch by opensearch-project.
the class TermsAggregatorTests method mapperServiceMock.
@Override
protected MapperService mapperServiceMock() {
MapperService mapperService = mock(MapperService.class);
DocumentMapper mapper = mock(DocumentMapper.class);
when(mapper.typeText()).thenReturn(new Text("_doc"));
when(mapper.type()).thenReturn("_doc");
when(mapperService.documentMapper()).thenReturn(mapper);
return mapperService;
}
Aggregations