/* SPDX-License-Identifier: Apache-2.0 * * The OpenSearch Contributors require contributions made to * this file be licensed under the Apache-2.0 license or a * compatible open source license. */ /* * Modifications Copyright OpenSearch Contributors. See * GitHub history for details. * * Licensed to Elasticsearch B.V. under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Elasticsearch B.V. licenses this file to you under * the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ using System; using OpenSearch.Net; namespace OpenSearch.Client { public class MultiGetOperation : IMultiGetOperation { public MultiGetOperation(Id id) { Id = id; Index = typeof(T); } public object Document { get; set; } public Id Id { get; set; } public IndexName Index { get; set; } public string Routing { get; set; } public Union Source { get; set; } public Fields StoredFields { get; set; } public long? Version { get; set; } public VersionType? VersionType { get; set; } bool IMultiGetOperation.CanBeFlattened => Index == null && Routing == null && Source == null && StoredFields == null; Type IMultiGetOperation.ClrType => typeof(T); } public class MultiGetOperationDescriptor : DescriptorBase, IMultiGetOperation>, IMultiGetOperation where T : class { public MultiGetOperationDescriptor() => Self.Index = Self.ClrType; /// /// when rest.action.multi.allow_explicit_index is set to false you can use this constructor to generate a multiget operation /// with no index and type set ///
		/// See also: https://github.com/elastic/elasticsearch/issues/3636
		/// 
///
public MultiGetOperationDescriptor(bool allowExplicitIndex) : this() { if (allowExplicitIndex) return; Self.Index = null; } bool IMultiGetOperation.CanBeFlattened => Self.Index == null && Self.Routing == null && Self.Source == null && Self.StoredFields == null; Type IMultiGetOperation.ClrType => typeof(T); Id IMultiGetOperation.Id { get; set; } IndexName IMultiGetOperation.Index { get; set; } string IMultiGetOperation.Routing { get; set; } Union IMultiGetOperation.Source { get; set; } Fields IMultiGetOperation.StoredFields { get; set; } long? IMultiGetOperation.Version { get; set; } VersionType? IMultiGetOperation.VersionType { get; set; } /// /// Manually set the index, default to the default index or the index set for the type on the connectionsettings. /// public MultiGetOperationDescriptor Index(IndexName index) => Assign(index, (a, v) => a.Index = v); public MultiGetOperationDescriptor Id(Id id) => Assign(id, (a, v) => a.Id = v); /// /// Control how the document's source is loaded /// public MultiGetOperationDescriptor Source(bool? sourceEnabled = true) => Assign(sourceEnabled, (a, v) => a.Source = v); /// /// Control how the document's source is loaded /// public MultiGetOperationDescriptor Source(Func, ISourceFilter> source) => Assign(new Union(source(new SourceFilterDescriptor())), (a, v) => a.Source = v); /// /// Set the routing for the get operation /// public MultiGetOperationDescriptor Routing(string routing) => Assign(routing, (a, v) => a.Routing = v); /// /// Allows to selectively load specific fields for each document /// represented by a search hit. Defaults to load the internal _source field. /// public MultiGetOperationDescriptor StoredFields(Func, IPromise> fields) => Assign(fields, (a, v) => a.StoredFields = v?.Invoke(new FieldsDescriptor())?.Value); public MultiGetOperationDescriptor StoredFields(Fields fields) => Assign(fields, (a, v) => a.StoredFields = v); public MultiGetOperationDescriptor Version(long? version) => Assign(version, (a, v) => a.Version = v); public MultiGetOperationDescriptor VersionType(VersionType? versionType) => Assign(versionType, (a, v) => a.VersionType = v); } }