forked from Jan-Bruun-Andersen/elastic-legacy-to-composable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlegacy2composable.jq
50 lines (49 loc) · 1.53 KB
/
legacy2composable.jq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# A small JQ script to convert an Elasticsearch template from legacy format to the
# new composable format.
#
# The new template will contain the following extras:
#
# - A meta section with:
# - The name of the source JSON file (the legacy template)
# - A note about the date when the template was converted
# - A template priority computed using a base-priority and the
# (reverse) legacy template order.
# E.g. with base = 300 and order = 2, the new priority will
# 300 + 1 - 2 = 299.
#
# - If absent in the legacy template:
# - A version number (yyyymmdd01)
# - In the mappings.properties section:
# - @version (keyword)
# - @timestamp (date)
#
# Written and concieved by Jan Bruun Andersen on a Thursday afternoon in 2023.
# Updated with code to handle inverse priority.
if (.template) then # Do nothing if a template section already exist.
.
else
. += {
"_meta": (
._meta | . += {
"filename": $fname,
"converted-by": ("legacy2composable on " + (now | strflocaltime("%F %T")))
}
),
"version": (try (.version // (now | strflocaltime("%Y%m%d01") | tonumber))),
"priority": (($base_prio | tonumber) + 1 - try (.order // 1)),
"template": {
"aliases": (try ( .aliases // {} )),
"settings": (try ( .settings // {} )),
"mappings": (try ( .mappings // {} )) | (
.properties."@version" = { type: "keyword" } |
.properties."@timestamp" = { type: "date" }
)
}
} |
del(
.order,
.aliases,
.settings,
.mappings
)
end