/* 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 System.Collections.Generic; using System.Runtime.Serialization; using OpenSearch.Net.Utf8Json; namespace OpenSearch.Client.Specification.IndicesApi { [MapsApi("indices.put_mapping.json")] [ReadAs(typeof(PutMappingRequest))] public partial interface IPutMappingRequest : ITypeMapping { } [InterfaceDataContract] [ReadAs(typeof(PutMappingRequest))] // ReSharper disable once UnusedTypeParameter public partial interface IPutMappingRequest where TDocument : class { } [DataContract] public partial class PutMappingRequest { /// public bool? DateDetection { get; set; } /// public Union Dynamic { get; set; } /// public IEnumerable DynamicDateFormats { get; set; } /// public IDynamicTemplateContainer DynamicTemplates { get; set; } /// public IFieldNamesField FieldNamesField { get; set; } /// public IDictionary Meta { get; set; } /// public bool? NumericDetection { get; set; } /// public IProperties Properties { get; set; } /// public IRoutingField RoutingField { get; set; } /// public IRuntimeFields RuntimeFields { get; set; } /// public ISizeField SizeField { get; set; } /// public ISourceField SourceField { get; set; } } // ReSharper disable once UnusedTypeParameter public partial class PutMappingRequest where TDocument : class { } [DataContract] public partial class PutMappingDescriptor where TDocument : class { bool? ITypeMapping.DateDetection { get; set; } Union ITypeMapping.Dynamic { get; set; } IEnumerable ITypeMapping.DynamicDateFormats { get; set; } IDynamicTemplateContainer ITypeMapping.DynamicTemplates { get; set; } IFieldNamesField ITypeMapping.FieldNamesField { get; set; } IDictionary ITypeMapping.Meta { get; set; } bool? ITypeMapping.NumericDetection { get; set; } IProperties ITypeMapping.Properties { get; set; } IRoutingField ITypeMapping.RoutingField { get; set; } IRuntimeFields ITypeMapping.RuntimeFields { get; set; } ISizeField ITypeMapping.SizeField { get; set; } ISourceField ITypeMapping.SourceField { get; set; } protected PutMappingDescriptor Assign(TValue value, Action assigner) => Fluent.Assign(this, value, assigner); /// /// Convenience method to map as much as it can based on OpenSearchType attributes set on the type. /// This method also automatically sets up mappings for primitive values types (e.g. int, long, double, DateTime...) /// Class types default to object and Enums to int /// Later calls can override whatever is set by this call. /// public PutMappingDescriptor AutoMap(IPropertyVisitor visitor = null, int maxRecursion = 0) { Self.Properties = Self.Properties.AutoMap(visitor, maxRecursion); return this; } /// public PutMappingDescriptor AutoMap(int maxRecursion) => AutoMap(null, maxRecursion); /// public PutMappingDescriptor Dynamic(Union dynamic) => Assign(dynamic, (a, v) => a.Dynamic = v); /// public PutMappingDescriptor Dynamic(bool? dynamic = true) => Assign(dynamic, (a, v) => a.Dynamic = v); /// public PutMappingDescriptor SizeField(Func sizeFieldSelector) => Assign(sizeFieldSelector, (a, v) => a.SizeField = v?.Invoke(new SizeFieldDescriptor())); /// public PutMappingDescriptor DisableSizeField(bool? disabled = true) => Assign(disabled, (a, v) => a.SizeField = new SizeField { Enabled = !v }); /// public PutMappingDescriptor DynamicDateFormats(IEnumerable dateFormats) => Assign(dateFormats, (a, v) => a.DynamicDateFormats = v); /// public PutMappingDescriptor DateDetection(bool? detect = true) => Assign(detect, (a, v) => a.DateDetection = v); /// public PutMappingDescriptor NumericDetection(bool? detect = true) => Assign(detect, (a, v) => a.NumericDetection = v); /// public PutMappingDescriptor SourceField(Func sourceFieldSelector) => Assign(sourceFieldSelector, (a, v) => a.SourceField = v?.Invoke(new SourceFieldDescriptor())); /// public PutMappingDescriptor RoutingField(Func, IRoutingField> routingFieldSelector) => Assign(routingFieldSelector, (a, v) => a.RoutingField = v?.Invoke(new RoutingFieldDescriptor())); /// public PutMappingDescriptor RuntimeFields(Func, IPromise> runtimeFieldsSelector) => Assign(runtimeFieldsSelector, (a, v) => a.RuntimeFields = v?.Invoke(new RuntimeFieldsDescriptor())?.Value); /// public PutMappingDescriptor RuntimeFields(Func, IPromise> runtimeFieldsSelector) where TSource : class => Assign(runtimeFieldsSelector, (a, v) => a.RuntimeFields = v?.Invoke(new RuntimeFieldsDescriptor())?.Value); /// public PutMappingDescriptor FieldNamesField(Func, IFieldNamesField> fieldNamesFieldSelector) => Assign(fieldNamesFieldSelector, (a, v) => a.FieldNamesField = v.Invoke(new FieldNamesFieldDescriptor())); /// public PutMappingDescriptor Meta(Func, FluentDictionary> metaSelector) => Assign(metaSelector, (a, v) => a.Meta = v(new FluentDictionary())); /// public PutMappingDescriptor Meta(Dictionary metaDictionary) => Assign(metaDictionary, (a, v) => a.Meta = v); /// public PutMappingDescriptor Properties(Func, IPromise> propertiesSelector) => Assign(propertiesSelector, (a, v) => a.Properties = v?.Invoke(new PropertiesDescriptor(a.Properties))?.Value); /// public PutMappingDescriptor DynamicTemplates(Func, IPromise> dynamicTemplatesSelector) => Assign(dynamicTemplatesSelector, (a, v) => a.DynamicTemplates = v?.Invoke(new DynamicTemplateContainerDescriptor())?.Value); } }