|
| 1 | +--- |
| 2 | +setup: |
| 3 | + - do: |
| 4 | + indices.create: |
| 5 | + index: sensor1 |
| 6 | + body: |
| 7 | + settings: |
| 8 | + number_of_shards: 1 |
| 9 | + number_of_replicas: 0 |
| 10 | + mappings: |
| 11 | + properties: |
| 12 | + timestamp: |
| 13 | + type: date |
| 14 | + message: |
| 15 | + type: keyword |
| 16 | + day_of_week: |
| 17 | + type: runtime_script |
| 18 | + runtime_type: keyword |
| 19 | + script: | |
| 20 | + emitValue(doc['timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT)); |
| 21 | + tomorrow: |
| 22 | + type: runtime_script |
| 23 | + runtime_type: date |
| 24 | + script: |
| 25 | + source: | |
| 26 | + for (def dt : doc['timestamp']) { |
| 27 | + emitValue(toEpochMilli(dt.plus(params.days, ChronoUnit.DAYS))); |
| 28 | + } |
| 29 | + params: |
| 30 | + days: 1 |
| 31 | + voltage: |
| 32 | + type: double |
| 33 | + voltage_times_ten: |
| 34 | + type: runtime_script |
| 35 | + runtime_type: long |
| 36 | + script: |
| 37 | + source: | |
| 38 | + for (double v : doc['voltage']) { |
| 39 | + emitValue((long)(v * params.multiplier)); |
| 40 | + } |
| 41 | + params: |
| 42 | + multiplier: 10 |
| 43 | + voltage_percent: |
| 44 | + type: runtime_script |
| 45 | + runtime_type: double |
| 46 | + script: |
| 47 | + source: | |
| 48 | + for (double v : doc['voltage']) { |
| 49 | + emitValue(v / params.max); |
| 50 | + } |
| 51 | + params: |
| 52 | + max: 5.8 |
| 53 | + ip: |
| 54 | + type: runtime_script |
| 55 | + runtime_type: ip |
| 56 | + script: |
| 57 | + source: | |
| 58 | + String m = doc["message"].value; |
| 59 | + int end = m.indexOf(" "); |
| 60 | + emitValue(m.substring(0, end)); |
| 61 | + over_v: |
| 62 | + type: runtime_script |
| 63 | + runtime_type: boolean |
| 64 | + script: |
| 65 | + source: | |
| 66 | + for (def v : doc['voltage']) { |
| 67 | + emitValue(v >= params.min_v); |
| 68 | + } |
| 69 | + params: |
| 70 | + min_v: 5.0 |
| 71 | + |
| 72 | + - do: |
| 73 | + bulk: |
| 74 | + index: sensor1 |
| 75 | + refresh: true |
| 76 | + body: | |
| 77 | + {"index":{}} |
| 78 | + {"timestamp": 1516729294000, "voltage": 5.2} |
| 79 | + {"index":{}} |
| 80 | + {"timestamp": 1516642894000, "voltage": 5.1} |
| 81 | + {"index":{}} |
| 82 | + {"timestamp": 1516556494000, "voltage": 5.8} |
| 83 | + {"index":{}} |
| 84 | + {"timestamp": 1516470094000, "voltage": 5.7} |
| 85 | + {"index":{}} |
| 86 | + {"timestamp": 1516383694000, "voltage": 5.6} |
| 87 | + {"index":{}} |
| 88 | + {"timestamp": 1516297294000, "voltage": 5.5} |
| 89 | +
|
| 90 | + - do: |
| 91 | + indices.create: |
| 92 | + index: sensor2 |
| 93 | + body: |
| 94 | + settings: |
| 95 | + number_of_shards: 1 |
| 96 | + number_of_replicas: 0 |
| 97 | + mappings: |
| 98 | + properties: |
| 99 | + message: |
| 100 | + type: keyword |
| 101 | + timestamp: |
| 102 | + type: date |
| 103 | + day_of_week: |
| 104 | + type: keyword |
| 105 | + tomorrow: |
| 106 | + type: date |
| 107 | + voltage: |
| 108 | + type: double |
| 109 | + voltage_times_ten: |
| 110 | + type: long |
| 111 | + voltage_percent: |
| 112 | + type: double |
| 113 | + ip: |
| 114 | + type: ip |
| 115 | + over_v: |
| 116 | + type: boolean |
| 117 | + |
| 118 | + - do: |
| 119 | + bulk: |
| 120 | + index: sensor2 |
| 121 | + refresh: true |
| 122 | + body: | |
| 123 | + {"index":{}} |
| 124 | + {"timestamp": 1516729294000, "day_of_week": "Monday", "voltage": 5.5, "voltage_times_ten": 55, "voltage_percent": 0.6} |
| 125 | + {"index":{}} |
| 126 | + {"timestamp": 1516642894000, "day_of_week": "Tuesday","voltage": 5.3, "voltage_times_ten": 53, "voltage_percent": 0.5} |
| 127 | + {"index":{}} |
| 128 | + {"timestamp": 1516556494000, "day_of_week": "Wednesday","voltage": 5.2, "voltage_times_ten": 52, "voltage_percent": 0.4} |
| 129 | + {"index":{}} |
| 130 | + {"timestamp": 1516470094000, "day_of_week": "Thursday","voltage": 5.1, "voltage_times_ten": 51, "voltage_percent": 0.3} |
| 131 | + {"index":{}} |
| 132 | + {"timestamp": 1516383694000, "day_of_week": "Friday","voltage": 5.6, "voltage_times_ten": 56, "voltage_percent": 0.7} |
| 133 | + {"index":{}} |
| 134 | + {"timestamp": 1516297294000, "day_of_week": "Saturday","voltage": 5.8, "voltage_times_ten": 58, "voltage_percent": 1} |
| 135 | +
|
| 136 | +--- |
| 137 | +"field capabilities": |
| 138 | + - do: |
| 139 | + field_caps: |
| 140 | + index: sensor* |
| 141 | + fields: [day_of_week, voltage_*, tomorrow, ip, over_v] |
| 142 | + |
| 143 | + - match: {indices: [sensor1, sensor2]} |
| 144 | + - match: {fields.day_of_week.keyword.searchable: true} |
| 145 | + - match: {fields.day_of_week.keyword.aggregatable: true} |
| 146 | + - is_false: fields.day_of_week.keyword.indices |
| 147 | + - match: {fields.voltage_times_ten.long.searchable: true} |
| 148 | + - match: {fields.voltage_times_ten.long.aggregatable: true} |
| 149 | + - is_false: fields.voltage_times_ten.long.indices |
| 150 | + - match: {fields.voltage_percent.double.searchable: true} |
| 151 | + - match: {fields.voltage_percent.double.aggregatable: true} |
| 152 | + - is_false: fields.voltage_percent.double.indices |
| 153 | + - match: {fields.tomorrow.date.searchable: true} |
| 154 | + - match: {fields.tomorrow.date.aggregatable: true} |
| 155 | + - is_false: fields.tomorrow.date.indices |
| 156 | + - match: {fields.ip.ip.searchable: true} |
| 157 | + - match: {fields.ip.ip.aggregatable: true} |
| 158 | + - is_false: fields.ip.ip.indices |
| 159 | + - match: {fields.over_v.boolean.searchable: true} |
| 160 | + - match: {fields.over_v.boolean.aggregatable: true} |
| 161 | + - is_false: fields.over_v.boolean.indices |
| 162 | + |
| 163 | +--- |
| 164 | +"terms agg - keyword": |
| 165 | + - do: |
| 166 | + search: |
| 167 | + index: sensor* |
| 168 | + body: |
| 169 | + aggs: |
| 170 | + dow: |
| 171 | + terms: |
| 172 | + field: day_of_week |
| 173 | + - match: {hits.total.value: 12} |
| 174 | + - match: {aggregations.dow.buckets.0.key: Friday} |
| 175 | + - match: {aggregations.dow.buckets.0.doc_count: 2} |
| 176 | + - match: {aggregations.dow.buckets.1.key: Monday} |
| 177 | + - match: {aggregations.dow.buckets.1.doc_count: 2} |
| 178 | + |
| 179 | +--- |
| 180 | +"match query - keyword": |
| 181 | + - do: |
| 182 | + search: |
| 183 | + index: sensor* |
| 184 | + body: |
| 185 | + query: |
| 186 | + match: |
| 187 | + day_of_week: Monday |
| 188 | + - match: {hits.total.value: 2} |
| 189 | + |
| 190 | +--- |
| 191 | +"terms agg - long": |
| 192 | + - do: |
| 193 | + search: |
| 194 | + index: sensor* |
| 195 | + body: |
| 196 | + aggs: |
| 197 | + v10: |
| 198 | + terms: |
| 199 | + field: voltage_times_ten |
| 200 | + - match: {hits.total.value: 12} |
| 201 | + - match: {aggregations.v10.buckets.0.key: 51} |
| 202 | + - match: {aggregations.v10.buckets.0.doc_count: 2} |
| 203 | + |
| 204 | +--- |
| 205 | +"range query - long": |
| 206 | + - do: |
| 207 | + search: |
| 208 | + index: sensor* |
| 209 | + body: |
| 210 | + query: |
| 211 | + range: |
| 212 | + voltage_times_ten: |
| 213 | + lt: 55 |
| 214 | + - match: {hits.total.value: 5} |
| 215 | + |
| 216 | +--- |
| 217 | +"terms agg - double": |
| 218 | + - do: |
| 219 | + search: |
| 220 | + index: sensor* |
| 221 | + body: |
| 222 | + aggs: |
| 223 | + v10: |
| 224 | + terms: |
| 225 | + field: voltage_percent |
| 226 | + - match: {hits.total.value: 12} |
| 227 | + - match: {aggregations.v10.buckets.0.key: 1.0} |
| 228 | + - match: {aggregations.v10.buckets.0.doc_count: 2} |
| 229 | + |
| 230 | +--- |
| 231 | +"range query - double": |
| 232 | + - do: |
| 233 | + search: |
| 234 | + index: sensor* |
| 235 | + body: |
| 236 | + query: |
| 237 | + range: |
| 238 | + voltage_percent: |
| 239 | + lt: .7 |
| 240 | + - match: {hits.total.value: 4} |
0 commit comments