我的目標是在 [hits] 欄位為空時發送警報。
這是我的結果:
hits: {
total: { value: 10000, relation: 'gte' },
max_score: 1,
hits: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object]
]
}
}
這是我的代碼:
const axios = require('axios');
const query = {
query: {
match: {
"kubernetes.pod.name.keyword" : "fcppaddy-596b798c77-9hwbh"
}
}
};
axios.get("https://tommaso.fachin:[email protected]:9200/filebeat-7.15.2/_search?
pretty", query)
.then((res) => {
console.log(res.data);
console.log(res.status);
console.log(JSON.stringify(res.data));
});
uj5u.com熱心網友回復:
我仍然不是 100%,但是從您的評論看來,您似乎想檢查 hits 中是否有任何內容,如果有,請為每個內容做一些事情:
if(hits.length > 0) {
hits.forEach((hit) => {
triggerAlarm()
})
}
所以顯然你可以選擇發送什么作為引數,triggerAlarm()但我認為這就是你所要求的
編輯,根據您的評論:
if(hits.hits.length > 0) {
hits.forEach((hit) => {
// for each item in hits.hits array, send mail
ModuloMail()
})
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/426555.html
標籤:javascript 节点.js 弹性搜索
