Ad
How Do I Check If Hits Has A Value Or Not?
My goal is to send an alarm if the [hits] field is empty.
This is my result:
hits: {
total: { value: 10000, relation: 'gte' },
max_score: 1,
hits: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object]
]
}
}
and this is my code:
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));
});
Ad
Answer
I'm still not 100%, but from your comments it seems like you want to check if hits has anything in it, and if so do something for each one:
if(hits.length > 0) {
hits.forEach((hit) => {
triggerAlarm()
})
}
So obviously you can choose what to send as a param to triggerAlarm()
but I think this is what you're asking for
Edit, based on your comment:
if(hits.hits.length > 0) {
hits.forEach((hit) => {
// for each item in hits.hits array, send mail
ModuloMail()
})
}
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad