|
| 1 | +using Nest.Resolvers.Converters; |
| 2 | +using Newtonsoft.Json; |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.Linq; |
| 6 | +using System.Text; |
| 7 | + |
| 8 | +namespace Nest |
| 9 | +{ |
| 10 | + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] |
| 11 | + [JsonConverter(typeof(ReadAsTypeConverter<ScriptedMetricsAggregator>))] |
| 12 | + public interface IScriptedMetricAggregator |
| 13 | + { |
| 14 | + [JsonProperty("init_script")] |
| 15 | + string InitScript { get; set; } |
| 16 | + |
| 17 | + [JsonProperty("init_script_file")] |
| 18 | + string InitScriptFile { get; set; } |
| 19 | + |
| 20 | + [JsonProperty("init_script_id")] |
| 21 | + string InitScriptId { get; set; } |
| 22 | + |
| 23 | + [JsonProperty("map_script")] |
| 24 | + string MapScript { get; set; } |
| 25 | + |
| 26 | + [JsonProperty("map_script_file")] |
| 27 | + string MapScriptFile { get; set; } |
| 28 | + |
| 29 | + [JsonProperty("map_script_id")] |
| 30 | + string MapScriptId { get; set; } |
| 31 | + |
| 32 | + [JsonProperty("combine_script")] |
| 33 | + string CombineScript { get; set; } |
| 34 | + |
| 35 | + [JsonProperty("combine_script_file")] |
| 36 | + string CombineScriptFile { get; set; } |
| 37 | + |
| 38 | + [JsonProperty("combine_script_id")] |
| 39 | + string CombineScriptId { get; set; } |
| 40 | + |
| 41 | + [JsonProperty("reduce_script")] |
| 42 | + string ReduceScript { get; set; } |
| 43 | + |
| 44 | + [JsonProperty("reduce_script_file")] |
| 45 | + string ReduceScriptFile { get; set; } |
| 46 | + |
| 47 | + [JsonProperty("reduce_script_id")] |
| 48 | + string ReduceScriptId { get; set; } |
| 49 | + |
| 50 | + [JsonProperty("reduce_params")] |
| 51 | + IDictionary<string, object> ReduceParams { get; set; } |
| 52 | + } |
| 53 | + |
| 54 | + public class ScriptedMetricsAggregator : MetricAggregator, IScriptedMetricAggregator |
| 55 | + { |
| 56 | + public string InitScript { get; set; } |
| 57 | + public string InitScriptFile { get; set; } |
| 58 | + public string InitScriptId { get; set; } |
| 59 | + public string MapScript { get; set; } |
| 60 | + public string MapScriptFile { get; set; } |
| 61 | + public string MapScriptId { get; set; } |
| 62 | + public string CombineScript { get; set; } |
| 63 | + public string CombineScriptFile { get; set; } |
| 64 | + public string CombineScriptId { get; set; } |
| 65 | + public string ReduceScript { get; set; } |
| 66 | + public string ReduceScriptFile { get; set; } |
| 67 | + public string ReduceScriptId { get; set; } |
| 68 | + public IDictionary<string, object> ReduceParams { get; set; } |
| 69 | + } |
| 70 | + |
| 71 | + public class ScriptedMetricAggregationDescriptor<T> |
| 72 | + : MetricAggregationBaseDescriptor<ScriptedMetricAggregationDescriptor<T>, T>, IScriptedMetricAggregator |
| 73 | + where T : class |
| 74 | + { |
| 75 | + IScriptedMetricAggregator Self { get { return this; } } |
| 76 | + |
| 77 | + string IScriptedMetricAggregator.InitScript { get; set; } |
| 78 | + string IScriptedMetricAggregator.InitScriptFile { get; set; } |
| 79 | + string IScriptedMetricAggregator.InitScriptId { get; set; } |
| 80 | + string IScriptedMetricAggregator.MapScript { get; set; } |
| 81 | + string IScriptedMetricAggregator.MapScriptFile { get; set; } |
| 82 | + string IScriptedMetricAggregator.MapScriptId { get; set; } |
| 83 | + string IScriptedMetricAggregator.CombineScript { get; set; } |
| 84 | + string IScriptedMetricAggregator.CombineScriptFile { get; set; } |
| 85 | + string IScriptedMetricAggregator.CombineScriptId { get; set; } |
| 86 | + string IScriptedMetricAggregator.ReduceScript { get; set; } |
| 87 | + string IScriptedMetricAggregator.ReduceScriptFile { get; set; } |
| 88 | + string IScriptedMetricAggregator.ReduceScriptId { get; set; } |
| 89 | + IDictionary<string, object> IScriptedMetricAggregator.ReduceParams { get; set; } |
| 90 | + |
| 91 | + public ScriptedMetricAggregationDescriptor<T> InitScript(string script) |
| 92 | + { |
| 93 | + this.Self.InitScript = script; |
| 94 | + return this; |
| 95 | + } |
| 96 | + |
| 97 | + public ScriptedMetricAggregationDescriptor<T> InitScriptFile(string file) |
| 98 | + { |
| 99 | + this.Self.InitScriptFile = file; |
| 100 | + return this; |
| 101 | + } |
| 102 | + |
| 103 | + public ScriptedMetricAggregationDescriptor<T> InitScriptId(string id) |
| 104 | + { |
| 105 | + this.Self.InitScriptId = id; |
| 106 | + return this; |
| 107 | + } |
| 108 | + |
| 109 | + public ScriptedMetricAggregationDescriptor<T> MapScript(string script) |
| 110 | + { |
| 111 | + this.Self.MapScript = script; |
| 112 | + return this; |
| 113 | + } |
| 114 | + |
| 115 | + public ScriptedMetricAggregationDescriptor<T> MapScriptFile(string file) |
| 116 | + { |
| 117 | + this.Self.MapScriptFile = file; |
| 118 | + return this; |
| 119 | + } |
| 120 | + |
| 121 | + public ScriptedMetricAggregationDescriptor<T> MapScriptId(string id) |
| 122 | + { |
| 123 | + this.Self.MapScriptId = id; |
| 124 | + return this; |
| 125 | + } |
| 126 | + |
| 127 | + public ScriptedMetricAggregationDescriptor<T> CombineScript(string script) |
| 128 | + { |
| 129 | + this.Self.CombineScript = script; |
| 130 | + return this; |
| 131 | + } |
| 132 | + |
| 133 | + public ScriptedMetricAggregationDescriptor<T> CombineScriptFile(string file) |
| 134 | + { |
| 135 | + this.Self.CombineScriptFile = file; |
| 136 | + return this; |
| 137 | + } |
| 138 | + |
| 139 | + public ScriptedMetricAggregationDescriptor<T> CombineScriptId(string id) |
| 140 | + { |
| 141 | + this.Self.CombineScriptId = id; |
| 142 | + return this; |
| 143 | + } |
| 144 | + |
| 145 | + public ScriptedMetricAggregationDescriptor<T> ReduceScript(string script) |
| 146 | + { |
| 147 | + this.Self.ReduceScript = script; |
| 148 | + return this; |
| 149 | + } |
| 150 | + |
| 151 | + public ScriptedMetricAggregationDescriptor<T> ReduceScriptFile(string file) |
| 152 | + { |
| 153 | + this.Self.ReduceScriptFile = file; |
| 154 | + return this; |
| 155 | + } |
| 156 | + |
| 157 | + public ScriptedMetricAggregationDescriptor<T> ReduceScriptId(string id) |
| 158 | + { |
| 159 | + this.Self.ReduceScriptId = id; |
| 160 | + return this; |
| 161 | + } |
| 162 | + |
| 163 | + public ScriptedMetricAggregationDescriptor<T> ReduceParams(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> paramSelector) |
| 164 | + { |
| 165 | + this.Self.ReduceParams = paramSelector(new FluentDictionary<string, object>()); |
| 166 | + return this; |
| 167 | + } |
| 168 | + } |
| 169 | +} |
0 commit comments