Search in sources :

Example 51 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("type1").startObject("properties").startObject("completion").field("type", "completion").startArray("contexts").startObject().field("name", "ctx").field("type", "category").endObject().endArray().endObject().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", "type1", "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 52 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("type1").startObject("properties").startObject("completion").field("type", "completion").startArray("contexts").startObject().field("name", "ctx").field("type", "category").endObject().endArray().endObject().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", "type1", "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 53 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("type1").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().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", "type1", "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)

Example 54 with DocumentMapper

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

the class CategoryContextMappingTests method testIndexingWithSimpleBooleanContexts.

public void testIndexingWithSimpleBooleanContexts() throws Exception {
    String mapping = Strings.toString(jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("completion").field("type", "completion").startArray("contexts").startObject().field("name", "ctx").field("type", "category").endObject().endArray().endObject().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", "type1", "1", BytesReference.bytes(jsonBuilder().startObject().startArray("completion").startObject().array("input", "suggestion5", "suggestion6", "suggestion7").startObject("contexts").field("ctx", true).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 55 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)

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 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)14 HashMap (java.util.HashMap)13 IOException (java.io.IOException)12 TextFieldMapper (org.opensearch.index.mapper.TextFieldMapper)12 Map (java.util.Map)11 IndexService (org.opensearch.index.IndexService)11 IndexSettings (org.opensearch.index.IndexSettings)11 Mapper (org.opensearch.index.mapper.Mapper)11 Collections (java.util.Collections)8 BytesRef (org.apache.lucene.util.BytesRef)8 Arrays (java.util.Arrays)7 Collection (java.util.Collection)7 DocValuesType (org.apache.lucene.index.DocValuesType)7