/* 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.Linq.Expressions; using System.Runtime.Serialization; using OpenSearch.Net.Utf8Json; namespace OpenSearch.Client { /// /// A multi-bucket value source based aggregation which finds "rare" terms — terms that are at the long-tail of the distribution /// and are not frequent. Conceptually, this is like a terms aggregation that is sorted by _count ascending. /// [InterfaceDataContract] [ReadAs(typeof(RareTermsAggregation))] public interface IRareTermsAggregation : IBucketAggregation { /// /// Terms that should be excluded from the aggregation /// [DataMember(Name = "exclude")] TermsExclude Exclude { get; set; } /// /// The field to find rare terms in /// [DataMember(Name = "field")] Field Field { get; set; } /// /// Terms that should be included in the aggregation /// [DataMember(Name = "include")] TermsInclude Include { get; set; } /// /// The maximum number of documents a term should appear in. /// Defaults to 1 /// [DataMember(Name = "max_doc_count")] long? MaximumDocumentCount { get; set; } /// /// The value that should be used if a document does not have the field being aggregated /// [DataMember(Name = "missing")] object Missing { get; set; } /// /// The precision of the internal CuckooFilters. Smaller precision leads to better approximation, /// but higher memory usage. Cannot be smaller than 0.00001. Defaults to 0.01 /// [DataMember(Name = "precision")] double? Precision { get; set; } } /// public class RareTermsAggregation : BucketAggregationBase, IRareTermsAggregation { internal RareTermsAggregation() { } public RareTermsAggregation(string name) : base(name) { } /// public TermsExclude Exclude { get; set; } /// public Field Field { get; set; } /// public TermsInclude Include { get; set; } /// public long? MaximumDocumentCount { get; set; } /// public object Missing { get; set; } /// public double? Precision { get; set; } internal override void WrapInContainer(AggregationContainer c) => c.RareTerms = this; } /// public class RareTermsAggregationDescriptor : BucketAggregationDescriptorBase, IRareTermsAggregation, T>, IRareTermsAggregation where T : class { TermsExclude IRareTermsAggregation.Exclude { get; set; } Field IRareTermsAggregation.Field { get; set; } TermsInclude IRareTermsAggregation.Include { get; set; } long? IRareTermsAggregation.MaximumDocumentCount { get; set; } object IRareTermsAggregation.Missing { get; set; } double? IRareTermsAggregation.Precision { get; set; } /// public RareTermsAggregationDescriptor Field(Field field) => Assign(field, (a, v) => a.Field = v); /// public RareTermsAggregationDescriptor Field(Expression> field) => Assign(field, (a, v) => a.Field = v); /// public RareTermsAggregationDescriptor MaximumDocumentCount(long? maximumDocumentCount) => Assign(maximumDocumentCount, (a, v) => a.MaximumDocumentCount = v); /// public RareTermsAggregationDescriptor Include(long partition, long numberOfPartitions) => Assign(new TermsInclude(partition, numberOfPartitions), (a, v) => a.Include = v); /// public RareTermsAggregationDescriptor Include(string includePattern) => Assign(new TermsInclude(includePattern), (a, v) => a.Include = v); /// public RareTermsAggregationDescriptor Include(IEnumerable values) => Assign(new TermsInclude(values), (a, v) => a.Include = v); /// public RareTermsAggregationDescriptor Exclude(string excludePattern) => Assign(new TermsExclude(excludePattern), (a, v) => a.Exclude = v); /// public RareTermsAggregationDescriptor Exclude(IEnumerable values) => Assign(new TermsExclude(values), (a, v) => a.Exclude = v); /// public RareTermsAggregationDescriptor Missing(object missing) => Assign(missing, (a, v) => a.Missing = v); /// public RareTermsAggregationDescriptor Precision(double? precision) => Assign(precision, (a, v) => a.Precision = v); } }