|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq.Expressions; |
| 4 | +using System.Runtime.Serialization; |
| 5 | +using Elasticsearch.Net.Utf8Json; |
| 6 | + |
| 7 | +namespace Nest |
| 8 | +{ |
| 9 | + /// <summary> |
| 10 | + /// A multi-bucket value source based aggregation which finds "rare" terms — terms that are at the long-tail of the distribution |
| 11 | + /// and are not frequent. Conceptually, this is like a terms aggregation that is sorted by _count ascending. |
| 12 | + /// </summary> |
| 13 | + [InterfaceDataContract] |
| 14 | + [ReadAs(typeof(RareTermsAggregation))] |
| 15 | + public interface IRareTermsAggregation : IBucketAggregation |
| 16 | + { |
| 17 | + /// <summary> |
| 18 | + /// Terms that should be excluded from the aggregation |
| 19 | + /// </summary> |
| 20 | + [DataMember(Name = "exclude")] |
| 21 | + TermsExclude Exclude { get; set; } |
| 22 | + |
| 23 | + /// <summary> |
| 24 | + /// The field to find rare terms in |
| 25 | + /// </summary> |
| 26 | + [DataMember(Name = "field")] |
| 27 | + Field Field { get; set; } |
| 28 | + |
| 29 | + /// <summary> |
| 30 | + /// Terms that should be included in the aggregation |
| 31 | + /// </summary> |
| 32 | + [DataMember(Name = "include")] |
| 33 | + TermsInclude Include { get; set; } |
| 34 | + |
| 35 | + /// <summary> |
| 36 | + /// The maximum number of documents a term should appear in. |
| 37 | + /// Defaults to <c>1</c> |
| 38 | + /// </summary> |
| 39 | + [DataMember(Name = "max_doc_count")] |
| 40 | + long? MaximumDocumentCount { get; set; } |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// The value that should be used if a document does not have the field being aggregated |
| 44 | + /// </summary> |
| 45 | + [DataMember(Name = "missing")] |
| 46 | + object Missing { get; set; } |
| 47 | + |
| 48 | + /// <summary> |
| 49 | + /// The precision of the internal CuckooFilters. Smaller precision leads to better approximation, |
| 50 | + /// but higher memory usage. Cannot be smaller than 0.00001. Defaults to 0.01 |
| 51 | + /// </summary> |
| 52 | + [DataMember(Name = "precision")] |
| 53 | + double? Precision { get; set; } |
| 54 | + } |
| 55 | + |
| 56 | + /// <inheritdoc cref="IRareTermsAggregation"/> |
| 57 | + public class RareTermsAggregation : BucketAggregationBase, IRareTermsAggregation |
| 58 | + { |
| 59 | + internal RareTermsAggregation() { } |
| 60 | + |
| 61 | + public RareTermsAggregation(string name) : base(name) { } |
| 62 | + |
| 63 | + /// <inheritdoc /> |
| 64 | + public TermsExclude Exclude { get; set; } |
| 65 | + /// <inheritdoc /> |
| 66 | + public Field Field { get; set; } |
| 67 | + /// <inheritdoc /> |
| 68 | + public TermsInclude Include { get; set; } |
| 69 | + /// <inheritdoc /> |
| 70 | + public long? MaximumDocumentCount { get; set; } |
| 71 | + /// <inheritdoc /> |
| 72 | + public object Missing { get; set; } |
| 73 | + /// <inheritdoc /> |
| 74 | + public double? Precision { get; set; } |
| 75 | + |
| 76 | + internal override void WrapInContainer(AggregationContainer c) => c.RareTerms = this; |
| 77 | + } |
| 78 | + |
| 79 | + /// <inheritdoc cref="IRareTermsAggregation"/> |
| 80 | + public class RareTermsAggregationDescriptor<T> |
| 81 | + : BucketAggregationDescriptorBase<RareTermsAggregationDescriptor<T>, IRareTermsAggregation, T>, IRareTermsAggregation |
| 82 | + where T : class |
| 83 | + { |
| 84 | + TermsExclude IRareTermsAggregation.Exclude { get; set; } |
| 85 | + Field IRareTermsAggregation.Field { get; set; } |
| 86 | + TermsInclude IRareTermsAggregation.Include { get; set; } |
| 87 | + long? IRareTermsAggregation.MaximumDocumentCount { get; set; } |
| 88 | + object IRareTermsAggregation.Missing { get; set; } |
| 89 | + double? IRareTermsAggregation.Precision { get; set; } |
| 90 | + |
| 91 | + /// <inheritdoc cref="IRareTermsAggregation.Field" /> |
| 92 | + public RareTermsAggregationDescriptor<T> Field(Field field) => Assign(field, (a, v) => a.Field = v); |
| 93 | + |
| 94 | + /// <inheritdoc cref="IRareTermsAggregation.Field" /> |
| 95 | + public RareTermsAggregationDescriptor<T> Field<TValue>(Expression<Func<T, TValue>> field) => Assign(field, (a, v) => a.Field = v); |
| 96 | + |
| 97 | + /// <inheritdoc cref="IRareTermsAggregation.MaximumDocumentCount" /> |
| 98 | + public RareTermsAggregationDescriptor<T> MaximumDocumentCount(long? maximumDocumentCount) => |
| 99 | + Assign(maximumDocumentCount, (a, v) => a.MaximumDocumentCount = v); |
| 100 | + |
| 101 | + /// <inheritdoc cref="IRareTermsAggregation.Include" /> |
| 102 | + public RareTermsAggregationDescriptor<T> Include(long partition, long numberOfPartitions) => |
| 103 | + Assign(new TermsInclude(partition, numberOfPartitions), (a, v) => a.Include = v); |
| 104 | + |
| 105 | + /// <inheritdoc cref="IRareTermsAggregation.Include" /> |
| 106 | + public RareTermsAggregationDescriptor<T> Include(string includePattern) => |
| 107 | + Assign(new TermsInclude(includePattern), (a, v) => a.Include = v); |
| 108 | + |
| 109 | + /// <inheritdoc cref="IRareTermsAggregation.Include" /> |
| 110 | + public RareTermsAggregationDescriptor<T> Include(IEnumerable<string> values) => |
| 111 | + Assign(new TermsInclude(values), (a, v) => a.Include = v); |
| 112 | + |
| 113 | + /// <inheritdoc cref="IRareTermsAggregation.Exclude" /> |
| 114 | + public RareTermsAggregationDescriptor<T> Exclude(string excludePattern) => |
| 115 | + Assign(new TermsExclude(excludePattern), (a, v) => a.Exclude = v); |
| 116 | + |
| 117 | + /// <inheritdoc cref="IRareTermsAggregation.Exclude" /> |
| 118 | + public RareTermsAggregationDescriptor<T> Exclude(IEnumerable<string> values) => |
| 119 | + Assign(new TermsExclude(values), (a, v) => a.Exclude = v); |
| 120 | + |
| 121 | + /// <inheritdoc cref="IRareTermsAggregation.Missing" /> |
| 122 | + public RareTermsAggregationDescriptor<T> Missing(object missing) => Assign(missing, (a, v) => a.Missing = v); |
| 123 | + |
| 124 | + /// <inheritdoc cref="IRareTermsAggregation.Precision" /> |
| 125 | + public RareTermsAggregationDescriptor<T> Precision(double? precision) => Assign(precision, (a, v) => a.Precision = v); |
| 126 | + } |
| 127 | +} |
0 commit comments