Search in sources :

Example 21 with DocumentMapper

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());
}
Also used : 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) MapperParsingException(org.opensearch.index.mapper.MapperParsingException) XContentParseException(org.opensearch.common.xcontent.XContentParseException)

Example 22 with DocumentMapper

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());
}
Also used : 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) MapperParsingException(org.opensearch.index.mapper.MapperParsingException) XContentParseException(org.opensearch.common.xcontent.XContentParseException)

Example 23 with DocumentMapper

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));
    };
}
Also used : SequenceNumbers(org.opensearch.index.seqno.SequenceNumbers) Arrays(java.util.Arrays) LongSupplier(java.util.function.LongSupplier) Term(org.apache.lucene.index.Term) TestThreadPool(org.opensearch.threadpool.TestThreadPool) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) IdOnlyFieldVisitor(org.opensearch.index.fieldvisitor.IdOnlyFieldVisitor) Version(org.opensearch.Version) PEER_RECOVERY(org.opensearch.index.engine.Engine.Operation.Origin.PEER_RECOVERY) ReferenceManager(org.apache.lucene.search.ReferenceManager) Strings(org.opensearch.common.Strings) MapperTestUtils(org.opensearch.index.MapperTestUtils) Document(org.apache.lucene.document.Document) REPLICA(org.opensearch.index.engine.Engine.Operation.Origin.REPLICA) MergePolicy(org.apache.lucene.index.MergePolicy) Map(java.util.Map) Lucene(org.opensearch.common.lucene.Lucene) Path(java.nio.file.Path) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) TimeValue(org.opensearch.common.unit.TimeValue) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Index(org.opensearch.index.Index) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) ReplicationTracker(org.opensearch.index.seqno.ReplicationTracker) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) CountDownLatch(java.util.concurrent.CountDownLatch) VersionType(org.opensearch.index.VersionType) Logger(org.apache.logging.log4j.Logger) Randomness(org.opensearch.common.Randomness) BytesArray(org.opensearch.common.bytes.BytesArray) LocalCheckpointTracker(org.opensearch.index.seqno.LocalCheckpointTracker) XContentType(org.opensearch.common.xcontent.XContentType) IndexCommit(org.apache.lucene.index.IndexCommit) CodecService(org.opensearch.index.codec.CodecService) LiveIndexWriterConfig(org.apache.lucene.index.LiveIndexWriterConfig) TranslogDeletionPolicies.createTranslogDeletionPolicy(org.opensearch.index.translog.TranslogDeletionPolicies.createTranslogDeletionPolicy) ThreadPool(org.opensearch.threadpool.ThreadPool) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ToLongBiFunction(java.util.function.ToLongBiFunction) Mapping(org.opensearch.index.mapper.Mapping) VersionFieldMapper(org.opensearch.index.mapper.VersionFieldMapper) ParsedDocument(org.opensearch.index.mapper.ParsedDocument) Bits(org.apache.lucene.util.Bits) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator) Before(org.junit.Before) ParseContext(org.opensearch.index.mapper.ParseContext) Versions(org.opensearch.common.lucene.uid.Versions) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Analyzer(org.apache.lucene.analysis.Analyzer) IOException(java.io.IOException) SourceFieldMapper(org.opensearch.index.mapper.SourceFieldMapper) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) AtomicLong(java.util.concurrent.atomic.AtomicLong) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) RetentionLeases(org.opensearch.index.seqno.RetentionLeases) TextField(org.apache.lucene.document.TextField) SeqNoFieldMapper(org.opensearch.index.mapper.SeqNoFieldMapper) Collections.shuffle(java.util.Collections.shuffle) IdFieldMapper(org.opensearch.index.mapper.IdFieldMapper) BiFunction(java.util.function.BiFunction) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService) StoredField(org.apache.lucene.document.StoredField) CheckedBiFunction(org.opensearch.common.CheckedBiFunction) MapperService(org.opensearch.index.mapper.MapperService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Directory(org.apache.lucene.store.Directory) After(org.junit.After) XContentFactory(org.opensearch.common.xcontent.XContentFactory) DummyShardLock(org.opensearch.test.DummyShardLock) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) TotalHitCountCollector(org.apache.lucene.search.TotalHitCountCollector) Sort(org.apache.lucene.search.Sort) BytesRef(org.apache.lucene.util.BytesRef) Collections.emptyList(java.util.Collections.emptyList) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) DirectoryReader(org.apache.lucene.index.DirectoryReader) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) TranslogConfig(org.opensearch.index.translog.TranslogConfig) Store(org.opensearch.index.store.Store) Collectors(java.util.stream.Collectors) Nullable(org.opensearch.common.Nullable) ClusterModule(org.opensearch.cluster.ClusterModule) IndexWriter(org.apache.lucene.index.IndexWriter) GatedCloseable(org.opensearch.common.concurrent.GatedCloseable) List(java.util.List) Matchers.equalTo(org.hamcrest.Matchers.equalTo) LeafReader(org.apache.lucene.index.LeafReader) IndexSettings(org.opensearch.index.IndexSettings) ReplicationResponse(org.opensearch.action.support.replication.ReplicationResponse) BigArrays(org.opensearch.common.util.BigArrays) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) IndexSearcher(org.apache.lucene.search.IndexSearcher) Uid(org.opensearch.index.mapper.Uid) IndexSettingsModule(org.opensearch.test.IndexSettingsModule) BytesReference(org.opensearch.common.bytes.BytesReference) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) NumericDocValues(org.apache.lucene.index.NumericDocValues) CompressedXContent(org.opensearch.common.compress.CompressedXContent) Function(java.util.function.Function) HashSet(java.util.HashSet) SourceToParse(org.opensearch.index.mapper.SourceToParse) Charset(java.nio.charset.Charset) Translog(org.opensearch.index.translog.Translog) PRIMARY(org.opensearch.index.engine.Engine.Operation.Origin.PRIMARY) AllocationId(org.opensearch.cluster.routing.AllocationId) DocumentMapper(org.opensearch.index.mapper.DocumentMapper) IOUtils(org.opensearch.core.internal.io.IOUtils) ShardId(org.opensearch.index.shard.ShardId) TermQuery(org.apache.lucene.search.TermQuery) Sets(org.opensearch.common.util.set.Sets) Field(org.apache.lucene.document.Field) CircuitBreakerService(org.opensearch.indices.breaker.CircuitBreakerService) Codec(org.apache.lucene.codecs.Codec) IndexRequest(org.opensearch.action.index.IndexRequest) Comparator(java.util.Comparator) Collections(java.util.Collections) DocumentMapper(org.opensearch.index.mapper.DocumentMapper) CompressedXContent(org.opensearch.common.compress.CompressedXContent) SourceToParse(org.opensearch.index.mapper.SourceToParse) MapperService(org.opensearch.index.mapper.MapperService) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 24 with DocumentMapper

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

Example 25 with DocumentMapper

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;
}
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 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