/* 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.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.Serialization; using OpenSearch.Net; using OpenSearch.Net.Utf8Json; namespace OpenSearch.Client { /// /// A mapping for a property type to a document field in OpenSearch /// [InterfaceDataContract] [JsonFormatter(typeof(PropertyFormatter))] public interface IProperty : IFieldMapping { /// /// Local property metadata that will not be stored in OpenSearch with the mappings /// [IgnoreDataMember] IDictionary LocalMetadata { get; set; } /// /// Metadata attached to the field. This metadata is stored in but opaque to OpenSearch. It is /// only useful for multiple applications that work on the same indices to share /// meta information about fields such as units. /// /// Field metadata enforces at most 5 entries, that keys have a length that /// is less than or equal to 20, and that values are strings whose length is less /// than or equal to 50. /// [DataMember(Name = "meta")] IDictionary Meta { get; set; } /// /// The name of the property /// [IgnoreDataMember] PropertyName Name { get; set; } /// /// The datatype of the property /// [DataMember(Name = "type")] string Type { get; set; } } /// /// A mapping for a property from a CLR type /// public interface IPropertyWithClrOrigin { /// /// The CLR property to which the mapping relates /// PropertyInfo ClrOrigin { get; set; } } /// [DebuggerDisplay("{DebugDisplay}")] public abstract class PropertyBase : IProperty, IPropertyWithClrOrigin { protected PropertyBase(FieldType type) => ((IProperty)this).Type = type.GetStringValue(); /// public IDictionary LocalMetadata { get; set; } /// public IDictionary Meta { get; set; } /// public PropertyName Name { get; set; } protected string DebugDisplay => $"Type: {((IProperty)this).Type ?? ""}, Name: {Name?.DebugDisplay ?? ""} "; public override string ToString() => DebugDisplay; /// /// Override for the property type, used for custom mappings /// protected string TypeOverride { get; set; } PropertyInfo IPropertyWithClrOrigin.ClrOrigin { get; set; } string IProperty.Type { get => TypeOverride; set => TypeOverride = value; } } }