@@ -39,9 +39,22 @@ const buildScript = (group) => ({
3939 source: `
4040 ctx._source.sort_group = params.group;
4141
42- // sort_end๋ end_date ๊ธฐ์ค epoch millis๋ก ํต์ผ
43- if (doc['end_date'].size() != 0) {
44- ctx._source.sort_end = doc['end_date'].value.toInstant().toEpochMilli();
42+ // sort_end๋ end_date ๊ธฐ์ค epoch millis๋ก ํต์ผ (updateByQuery์์๋ doc[] ์ฌ์ฉ ๋ถ๊ฐ)
43+ if (ctx._source.containsKey('end_date') && ctx._source.end_date != null) {
44+ def v = ctx._source.end_date;
45+
46+ // end_date๊ฐ ์ซ์(epoch millis)์ธ ๊ฒฝ์ฐ
47+ if (v instanceof Number) {
48+ ctx._source.sort_end = ((Number)v).longValue();
49+
50+ // end_date๊ฐ ISO ๋ฌธ์์ด(์: 2026-02-20T14:00:00.000Z)์ธ ๊ฒฝ์ฐ
51+ } else if (v instanceof String) {
52+ ctx._source.sort_end = java.time.Instant.parse((String)v).toEpochMilli();
53+
54+ // ๊ธฐํ ์์ธ ์ผ์ด์ค๋ ๋ค๋ก ๋ณด๋
55+ } else {
56+ ctx._source.sort_end = 9223372036854775807L;
57+ }
4558 } else {
4659 ctx._source.sort_end = 9223372036854775807L; // ์์(์์)๋ ๋งจ ๋ค๋ก
4760 }
@@ -77,14 +90,17 @@ async function reclassifySortGroups() {
7790 console.log("[range] now=", nowIso);
7891 console.log("[range] kstToday(UTC) start=", utcStartIso, "end=", utcEndIso);
7992
93+ // 1) ์์(2): end_date ์์
8094 // 1) ์์(2): end_date ์์
8195 await updateGroup({
8296 name: "ALWAYS(2)",
8397 group: 2,
8498 query: {
8599 bool: {
86- must_not: [{ exists: { field: "end_date" } }],
87- must_not: [{ term: { sort_group: 2 } }],
100+ must_not: [
101+ { exists: { field: "end_date" } },
102+ { term: { sort_group: 2 } },
103+ ],
88104 },
89105 },
90106 });
0 commit comments