Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
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:Indigestione!@elastic.gnet.it:9200/filebeat-7.15.2/_search? 
 pretty", query)
  .then((res) => {
    console.log(res.data);
    console.log(res.status);
console.log(JSON.stringify(res.data));
  });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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()
  })
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!