我希望以文本格式(如星期一、星期二等)获得星期几的聚合结果。我有以下聚合,其中我获得星期几的结果,但以数字格式(如1表示星期一,2表示星期二等)获得。
"aggs": { "perWeekDay": { "terms": { "script": "doc['order_datetime'].date.dayOfWeek" } } }
更新:我使用脚本来做这个,因为我想在kibana中添加自定义字段,在那里我需要提到这个脚本。
icnyk63a1#
通过使用条件执行一些脚本工作解决了相同问题。
"aggs": { "perWeekDay": { "terms": { "script": "(doc['order_datetime'].date.dayOfWeek == 1 ? 'Monday' : (doc['order_datetime'].date.dayOfWeek == 2 ? 'Tuesday' : ((doc['order_datetime'].date.dayOfWeek == 3 ? 'Wednesday' : ((doc['order_datetime'].date.dayOfWeek == 4 ? 'Thursday' : ((doc['order_datetime'].date.dayOfWeek == 5 ? 'Friday' : ((doc['order_datetime'].date.dayOfWeek == 6 ? 'Saturday' : 'Sunday'))))))))))" } } }
h5qlskok2#
或者你可以这样做doc['timestamp'].date.dayOfWeek + " (" + ["", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][doc['timestamp'].date.dayOfWeek] + ")"
doc['timestamp'].date.dayOfWeek + " (" + ["", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][doc['timestamp'].date.dayOfWeek] + ")"
qeeaahzv3#
你可以很容易地通过这样做:
GET <YourIndexName>/_search { "size": 0, "aggs": { "perWeekDay": { "terms": { "script": "doc['order_datetime'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT)" } } } }
3条答案
按热度按时间icnyk63a1#
通过使用条件执行一些脚本工作解决了相同问题。
h5qlskok2#
或者你可以这样做
doc['timestamp'].date.dayOfWeek + " (" + ["", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][doc['timestamp'].date.dayOfWeek] + ")"
qeeaahzv3#
你可以很容易地通过这样做: