/* 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.Linq.Expressions; using System.Runtime.Serialization; using OpenSearch.Net; using OpenSearch.Net.Utf8Json; namespace OpenSearch.Client { /// /// The configuration for a field or script that provides a value or weight /// for /// [InterfaceDataContract] [ReadAs(typeof(WeightedAverageValue))] public interface IWeightedAverageValue { /// /// The field that values should be extracted from /// [DataMember(Name ="field")] Field Field { get; set; } /// /// defines how documents that are missing a value should be treated. /// The default behavior is different for value and weight: /// By default, if the value field is missing the document is ignored and the aggregation /// moves on to the next document. /// If the weight field is missing, it is assumed to have a weight of 1 (like a normal average). /// [DataMember(Name ="missing")] double? Missing { get; set; } /// /// A script to derive the value and the weight from /// [DataMember(Name ="script")] IScript Script { get; set; } } /// public class WeightedAverageValue : IWeightedAverageValue { internal WeightedAverageValue() { } public WeightedAverageValue(Field field) => Field = field; public WeightedAverageValue(IScript script) => Script = script; /// public Field Field { get; set; } /// public double? Missing { get; set; } /// public IScript Script { get; set; } } /// public class WeightedAverageValueDescriptor : DescriptorBase, IWeightedAverageValue> , IWeightedAverageValue where T : class { Field IWeightedAverageValue.Field { get; set; } double? IWeightedAverageValue.Missing { get; set; } IScript IWeightedAverageValue.Script { get; set; } /// public WeightedAverageValueDescriptor Field(Field field) => Assign(field, (a, v) => a.Field = v); /// public WeightedAverageValueDescriptor Field(Expression> field) => Assign(field, (a, v) => a.Field = v); /// public virtual WeightedAverageValueDescriptor Script(string script) => Assign(new InlineScript(script), (a, v) => a.Script = v); /// public virtual WeightedAverageValueDescriptor Script(Func scriptSelector) => Assign(scriptSelector, (a, v) => a.Script = v?.Invoke(new ScriptDescriptor())); /// public WeightedAverageValueDescriptor Missing(double? missing) => Assign(missing, (a, v) => a.Missing = v); } /// /// The type of value /// [StringEnum] public enum ValueType { /// A string value [EnumMember(Value = "string")] String, /// A long value that can be used to represent byte, short, integer and long [EnumMember(Value = "long")] Long, /// A double value that can be used to represent float and double [EnumMember(Value = "double")] Double, /// A number value [EnumMember(Value = "number")] Number, /// A date value [EnumMember(Value = "date")] Date, /// A date nanos value [EnumMember(Value = "date_nanos")] DateNanos, /// An IP value [EnumMember(Value = "ip")] Ip, /// A numeric value [EnumMember(Value = "numeric")] Numeric, /// A geo_point value [EnumMember(Value = "geo_point")] GeoPoint, /// A boolean value [EnumMember(Value = "boolean")] Boolean, } }