// TestTerms GET flower-business-*/_search {"aggs":{"aggs":{"terms":{"field":"platform","order":[{"_count":"desc"}],"size":10}}},"query":{"bool":{"filter":[{"query_string":{"query":"*"}},{"range":{"@timestamp":{"format":"epoch_second","from":1688313600,"include_lower":true,"include_upper":false,"to":1689004799}}}]}},"size":0}
1 2 3
// TestTerms_SubAggregation GET flower-business-*/_search {"aggs":{"aggs":{"aggregations":{"platform":{"terms":{"field":"platform"}}},"terms":{"field":"appVersion","order":[{"_count":"desc"}],"size":10}}},"query":{"bool":{"filter":[{"query_string":{"query":"*"}},{"range":{"@timestamp":{"format":"epoch_second","from":1688313600,"include_lower":true,"include_upper":false,"to":1689004799}}}]}},"size":0}
// TestDateHistogram GET flower-business-*/_search {"aggs":{"aggs":{"date_histogram":{"calendar_interval":"1d","field":"@timestamp","time_zone":"Asia/Shanghai"}}},"query":{"bool":{"filter":[{"query_string":{"query":"*"}},{"range":{"@timestamp":{"format":"epoch_second","from":1688313600,"include_lower":true,"include_upper":false,"to":1689004799}}}]}},"size":0}
1 2 3
// TestDateHistogram_SubAggregation GET flower-business-*/_search {"aggs":{"aggs":{"aggregations":{"dau":{"cardinality":{"field":"uuid"}}},"date_histogram":{"calendar_interval":"1d","field":"@timestamp","time_zone":"Asia/Shanghai"}}},"query":{"bool":{"filter":[{"query_string":{"query":"*"}},{"range":{"@timestamp":{"format":"epoch_second","from":1688313600,"include_lower":true,"include_upper":false,"to":1689004799}}}]}},"size":0}
1 2 3
// TestDateHistogram_RuntimeMappings GET flower-business-*/_search {"aggs":{"aggs":{"aggregations":{"regDay":{"aggregations":{"dau":{"cardinality":{"field":"uuid"}}},"date_histogram":{"calendar_interval":"1d","field":"register_time_date","time_zone":"Asia/Shanghai"}}},"date_histogram":{"calendar_interval":"1d","field":"@timestamp","time_zone":"Asia/Shanghai"}}},"query":{"bool":{"filter":[{"query_string":{"query":"_exists_:register_time"}},{"range":{"@timestamp":{"format":"epoch_second","from":1688313600,"include_lower":true,"include_upper":false,"to":1689004799}}}]}},"runtime_mappings":{"register_time_date":{"script":{"source":"if(doc['register_time'].size()!=0) {emit(doc['register_time'].value*1000);} else {emit(0);}"},"type":"date"}},"size":0}
// TestFilters GET flower-business-*/_search {"aggs":{"aggs":{"filters":{"filters":{"itemsLog":{"query_string":{"query":"LogType:itemsLog"}},"loginLog":{"query_string":{"query":"LogType:loginLog"}},"scoreLog":{"query_string":{"query":"LogType:scoreLog"}}}}}},"query":{"bool":{"filter":[{"query_string":{"query":"*"}},{"range":{"@timestamp":{"format":"epoch_second","from":1688313600,"include_lower":true,"include_upper":false,"to":1689004799}}}]}},"size":0}
1 2 3
// TestFilters_SubAggregation GET flower-business-*/_search {"aggs":{"aggs":{"aggregations":{"count":{"cardinality":{"field":"uuid"}}},"filters":{"filters":{"itemsLog":{"query_string":{"query":"LogType:itemsLog"}},"loginLog":{"query_string":{"query":"LogType:loginLog"}},"scoreLog":{"query_string":{"query":"LogType:scoreLog"}}}}}},"query":{"bool":{"filter":[{"query_string":{"query":"*"}},{"range":{"@timestamp":{"format":"epoch_second","from":1688313600,"include_lower":true,"include_upper":false,"to":1689004799}}}]}},"size":0}
// TestComposite GET flower-business-*/_search {"aggs":{"aggs":{"composite":{"size":10000,"sources":[{"customerId":{"terms":{"field":"customerId"}}}]}}},"query":{"bool":{"filter":[{"query_string":{"query":"*"}},{"range":{"@timestamp":{"format":"epoch_second","from":1688054400,"include_lower":true,"include_upper":false,"to":1688745599}}}]}},"size":0}
1 2 3
// TestComposite_SubAggregation GET flower-business-*/_search {"aggs":{"aggs":{"aggregations":{"lastLevel":{"max":{"field":"topLevel"}},"lastLoginIn":{"max":{"field":"actTime"}}},"composite":{"size":10000,"sources":[{"customerId":{"terms":{"field":"customerId"}}}]}}},"query":{"bool":{"filter":[{"query_string":{"query":"*"}},{"range":{"@timestamp":{"format":"epoch_second","from":1688054400,"include_lower":true,"include_upper":false,"to":1688745599}}}]}},"size":0}
1 2 3
// TestComposite_DateHistogram GET flower-business-*/_search {"aggs":{"aggs":{"composite":{"size":10000,"sources":[{"actDay":{"date_histogram":{"calendar_interval":"1d","field":"@timestamp","time_zone":"Asia/Shanghai"}}},{"customerId":{"terms":{"field":"customerId"}}}]}}},"query":{"bool":{"filter":[{"query_string":{"query":"*"}},{"range":{"@timestamp":{"format":"epoch_second","from":1688054400,"include_lower":true,"include_upper":false,"to":1688745599}}}]}},"size":0}
1 2 3
// TestComposite_DateHistogram_RuntimeMappings GET flower-business-*/_search {"runtime_mappings":{"register_time_date":{"type":"date","script":{"source":"if(doc['register_time'].size()!=0)\n {emit(doc['register_time'].value*1000);}\n else{emit(0);}"}}},"aggs":{"aggs":{"composite":{"size":10000,"sources":[{"actDay":{"date_histogram":{"calendar_interval":"1d","field":"@timestamp","time_zone":"Asia/Shanghai"}}},{"regDay":{"date_histogram":{"calendar_interval":"1d","field":"register_time_date","time_zone":"Asia/Shanghai"}}},{"customerId":{"terms":{"field":"customerId"}}},{"register_time":{"terms":{"field":"register_time"}}}]}}},"query":{"bool":{"filter":[{"query_string":{"query":"*"}},{"range":{"@timestamp":{"format":"epoch_second","from":1687968000,"include_lower":true,"include_upper":false,"to":1688659199}}}]}},"size":0}
1 2 3
// TestComposite_DateHistogram_Filters GET flower-business-*/_search {"aggs":{"aggs":{"aggregations":{"dau":{"aggregations":{"count":{"cardinality":{"field":"uuid"}}},"filter":{"query_string":{"query":"LogType:loginLog"}}},"itemNumbers":{"aggregations":{"sum":{"sum":{"field":"number"}}},"filter":{"query_string":{"query":"LogType:itemsLog"}}},"levelCount":{"filter":{"query_string":{"query":"LogType:scoreLog"}}}},"composite":{"size":10000,"sources":[{"actDay":{"date_histogram":{"calendar_interval":"1d","field":"@timestamp","time_zone":"Asia/Shanghai"}}}]}}},"query":{"bool":{"filter":[{"query_string":{"query":"*"}},{"range":{"@timestamp":{"format":"epoch_second","from":1688054400,"include_lower":true,"include_upper":false,"to":1688745599}}}]}},"size":0}
1 2 3
// TestComposite_DateHistogram_Range GET flower-business-*/_search {"aggs":{"aggs":{"aggregations":{"level":{"range":{"field":"topLevel","ranges":[{"from":0,"key":"0~500","to":500},{"from":501,"key":"501~"}]}}},"composite":{"size":10000,"sources":[{"actDay":{"date_histogram":{"calendar_interval":"1d","field":"@timestamp","time_zone":"Asia/Shanghai"}}}]}}},"query":{"bool":{"filter":[{"query_string":{"query":"LogType:loginLog"}},{"range":{"@timestamp":{"format":"epoch_second","from":1688054400,"include_lower":true,"include_upper":false,"to":1688745599}}}]}},"size":0}
Example: Use scripted fields in Kibana to add day_x (days since unlock) field for unlock metrics. Add path: Stack Management > Index Patterns > flower-business-* > Scripted fields > Add scripted field
1 2 3 4 5 6 7 8
if (doc["msg.code"].size() != 0 && doc["msg.code"].value == 1040 && doc["msg.eventName"].value == "unlockInstanceMap"){ def now_ts = newDate().getTime(); def now_inst = Instant.ofEpochMilli(now_ts); ZonedDateTime now = ZonedDateTime.ofInstant(now_inst,ZoneId.of('Z')); ZonedDateTime lockTime = ZonedDateTime.ofInstant(doc['@timestamp'].value.toInstant(), ZoneId.of('Z')); def day = ChronoUnit.DAYS.between(lockTime, now); return day }