Search in sources :

Example 26 with DocumentMapper

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);
}
Also used : MappingLookup(org.opensearch.index.mapper.MappingLookup) DocumentMapper(org.opensearch.index.mapper.DocumentMapper)

Example 27 with DocumentMapper

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;
}
Also used : DocumentMapper(org.opensearch.index.mapper.DocumentMapper) Text(org.opensearch.common.text.Text) MapperService(org.opensearch.index.mapper.MapperService)

Example 28 with DocumentMapper

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);
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) KeywordFieldMapper(org.opensearch.index.mapper.KeywordFieldMapper) Mapper(org.opensearch.index.mapper.Mapper) DocumentMapper(org.opensearch.index.mapper.DocumentMapper) TextFieldMapper(org.opensearch.index.mapper.TextFieldMapper) ParsedDocument(org.opensearch.index.mapper.ParsedDocument) DocumentMapper(org.opensearch.index.mapper.DocumentMapper) CompressedXContent(org.opensearch.common.compress.CompressedXContent) SourceToParse(org.opensearch.index.mapper.SourceToParse) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 29 with DocumentMapper

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);
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) KeywordFieldMapper(org.opensearch.index.mapper.KeywordFieldMapper) Mapper(org.opensearch.index.mapper.Mapper) DocumentMapper(org.opensearch.index.mapper.DocumentMapper) TextFieldMapper(org.opensearch.index.mapper.TextFieldMapper) ParsedDocument(org.opensearch.index.mapper.ParsedDocument) DocumentMapper(org.opensearch.index.mapper.DocumentMapper) CompressedXContent(org.opensearch.common.compress.CompressedXContent) SourceToParse(org.opensearch.index.mapper.SourceToParse) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 30 with DocumentMapper

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);
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) KeywordFieldMapper(org.opensearch.index.mapper.KeywordFieldMapper) Mapper(org.opensearch.index.mapper.Mapper) DocumentMapper(org.opensearch.index.mapper.DocumentMapper) TextFieldMapper(org.opensearch.index.mapper.TextFieldMapper) ParsedDocument(org.opensearch.index.mapper.ParsedDocument) DocumentMapper(org.opensearch.index.mapper.DocumentMapper) CompressedXContent(org.opensearch.common.compress.CompressedXContent) SourceToParse(org.opensearch.index.mapper.SourceToParse) Matchers.containsString(org.hamcrest.Matchers.containsString) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Aggregations

DocumentMapper (org.opensearch.index.mapper.DocumentMapper)55 ParsedDocument (org.opensearch.index.mapper.ParsedDocument)23 Matchers.containsString (org.hamcrest.Matchers.containsString)22 CompressedXContent (org.opensearch.common.compress.CompressedXContent)19 SourceToParse (org.opensearch.index.mapper.SourceToParse)19 IndexableField (org.apache.lucene.index.IndexableField)17 MapperService (org.opensearch.index.mapper.MapperService)17 HashMap (java.util.HashMap)14 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)14 Mapper (org.opensearch.index.mapper.Mapper)12 TextFieldMapper (org.opensearch.index.mapper.TextFieldMapper)12 IOException (java.io.IOException)11 Map (java.util.Map)11 IndexService (org.opensearch.index.IndexService)11 IndexSettings (org.opensearch.index.IndexSettings)11 Collections (java.util.Collections)8 BytesRef (org.apache.lucene.util.BytesRef)8 Arrays (java.util.Arrays)7 DocValuesType (org.apache.lucene.index.DocValuesType)7 IndexOptions (org.apache.lucene.index.IndexOptions)7