Update page updatedAt when updating labels

This commit is contained in:
Hongbo Wu 2022-06-28 12:03:37 +08:00
parent 00f38d1134
commit c08afe6451

View file

@ -15,13 +15,16 @@ export const addLabelInPage = async (
body: {
script: {
source: `if (ctx._source.labels == null) {
ctx._source.labels = [params.label]
ctx._source.labels = [params.label];
ctx._source.updatedAt = params.updatedAt
} else if (!ctx._source.labels.any(label -> label.name == params.label.name)) {
ctx._source.labels.add(params.label)
ctx._source.labels.add(params.label) ;
ctx._source.updatedAt = params.updatedAt
} else { ctx.op = 'none' }`,
lang: 'painless',
params: {
label: label,
updatedAt: new Date(),
},
},
},
@ -99,20 +102,22 @@ export const deleteLabel = async (
ctx: PageContext
): Promise<boolean> => {
try {
console.log('deleting label', label)
const { body } = await client.updateByQuery({
index: INDEX_ALIAS,
body: {
script: {
source: `if (ctx._source.highlights != null && ctx._source.highlights[0].labels != null) {
ctx._source.highlights[0].labels.removeIf(label -> label.name == params.label)
ctx._source.highlights[0].labels.removeIf(label -> label.name == params.label);
ctx._source.updatedAt = params.updatedAt
}
if (ctx._source.labels != null) {
ctx._source.labels.removeIf(label -> label.name == params.label)
ctx._source.labels.removeIf(label -> label.name == params.label);
ctx._source.updatedAt = params.updatedAt
}`,
lang: 'painless',
params: {
label: label,
updatedAt: new Date(),
},
},
query: {
@ -178,15 +183,18 @@ export const updateLabel = async (
script: {
source: `if (ctx._source.labels != null) {
ctx._source.labels.removeIf(l -> l.id == params.label.id);
ctx._source.labels.add(params.label)
ctx._source.labels.add(params.label);
ctx._source.updatedAt = params.updatedAt
}
if (ctx._source.highlights != null) {
ctx._source.highlights[0].labels.removeIf(l -> l.id == params.label.id);
ctx._source.highlights[0].labels.add(params.label)
ctx._source.highlights[0].labels.add(params.label);
ctx._source.updatedAt = params.updatedAt
}`,
lang: 'painless',
params: {
label: label,
updatedAt: new Date(),
},
},
query: {
@ -252,10 +260,12 @@ export const setLabelsForHighlight = async (
index: INDEX_ALIAS,
body: {
script: {
source: `ctx._source.highlights[0].labels = params.labels`,
source: `ctx._source.highlights[0].labels = params.labels;
ctx._source.updatedAt = params.updatedAt`,
lang: 'painless',
params: {
labels: labels,
updatedAt: new Date(),
},
},
query: {