use of org.opensearch.index.mapper.DocumentMapper in project OpenSearch by opensearch-project.
the class ParentJoinFieldMapper method getMapper.
/**
* Returns the {@link ParentJoinFieldMapper} associated with the <code>service</code> or null
* if there is no parent-join field in this mapping.
*/
public static ParentJoinFieldMapper getMapper(MapperService service) {
MetaJoinFieldMapper.MetaJoinFieldType fieldType = (MetaJoinFieldMapper.MetaJoinFieldType) service.fieldType(MetaJoinFieldMapper.NAME);
if (fieldType == null) {
return null;
}
DocumentMapper mapper = service.documentMapper();
String joinField = fieldType.getJoinField();
MappingLookup fieldMappers = mapper.mappers();
return (ParentJoinFieldMapper) fieldMappers.getMapper(joinField);
}
use of org.opensearch.index.mapper.DocumentMapper in project OpenSearch by opensearch-project.
the class RareTermsAggregatorTests 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 CategoryContextMappingTests method testIndexingWithNoContexts.
public void testIndexingWithNoContexts() 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));
Mapper fieldMapper = defaultMapper.mappers().getMapper("completion");
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "1", BytesReference.bytes(jsonBuilder().startObject().startArray("completion").startObject().array("input", "suggestion1", "suggestion2").field("weight", 3).endObject().startObject().array("input", "suggestion3", "suggestion4").field("weight", 4).endObject().startObject().array("input", "suggestion5", "suggestion6", "suggestion7").field("weight", 5).endObject().endArray().endObject()), XContentType.JSON));
IndexableField[] fields = parsedDocument.rootDoc().getFields(fieldMapper.name());
assertContextSuggestFields(fields, 7);
}
use of org.opensearch.index.mapper.DocumentMapper in project OpenSearch by opensearch-project.
the class CategoryContextMappingTests method testIndexingWithSimpleNumberContexts.
public void testIndexingWithSimpleNumberContexts() 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));
Mapper fieldMapper = defaultMapper.mappers().getMapper("completion");
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "1", BytesReference.bytes(jsonBuilder().startObject().startArray("completion").startObject().array("input", "suggestion5", "suggestion6", "suggestion7").startObject("contexts").field("ctx", 100).endObject().field("weight", 5).endObject().endArray().endObject()), XContentType.JSON));
IndexableField[] fields = parsedDocument.rootDoc().getFields(fieldMapper.name());
assertContextSuggestFields(fields, 3);
}
use of org.opensearch.index.mapper.DocumentMapper in project OpenSearch by opensearch-project.
the class CategoryContextMappingTests method testIndexingWithMultipleContexts.
public void testIndexingWithMultipleContexts() 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().startObject().field("name", "type").field("type", "category").endObject().endArray().endObject().endObject().endObject());
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
Mapper fieldMapper = defaultMapper.mappers().getMapper("completion");
XContentBuilder builder = jsonBuilder().startObject().startArray("completion").startObject().array("input", "suggestion5", "suggestion6", "suggestion7").field("weight", 5).startObject("contexts").array("ctx", "ctx1", "ctx2", "ctx3").array("type", "typr3", "ftg").endObject().endObject().endArray().endObject();
ParsedDocument parsedDocument = defaultMapper.parse(new SourceToParse("test", "1", BytesReference.bytes(builder), XContentType.JSON));
IndexableField[] fields = parsedDocument.rootDoc().getFields(fieldMapper.name());
assertContextSuggestFields(fields, 3);
}
Aggregations