Angular ElasticSearch:无法检索昨天和今天的记录

e4eetjau  于 2021-06-10  发布在  ElasticSearch
关注(0)|答案(0)|浏览(204)

我试图通过订阅方法查询elk集群,但它不返回今天和昨天的记录。这是一个向集群发出post请求的函数,我在url末尾使用\u search来执行搜索:

getIncomingMessages(from:Number, size:Number, fromTime: String, toTime:String, sort:String){

 let query= { "query": {
  "bool": {
      "must": [
          {
              "range": {
                  "@timestamp": {
                      "gte": fromTime,
                       "lte":  toTime
                  }
              }
          },
          {
              "query_string": {
                  "query": "json.message:incoming"
              }
          }
      ]
  }},"sort": [
{
  "@timestamp": {
    "order": sort
  }
}], "from": from, "size": size} return this.http.post(this.url1, query) //url1 is just the url of the cluster

这是订阅方法:

getIncomingMessages(from:Number, size:Number, fromDate: String, toDate:String, sort:String){

this.inObs = this.dataService.getIncomingMessages(from, size, fromDate, toDate, sort).subscribe(data =>{

  let msg = JSON.parse(JSON.stringify(data))
  for(let hit in msg.hits.hits){
    this.incomingMessages.push(msg.hits.hits[hit]["_source"]["json"]["message"])
    this.incomingMessagesApp.push(msg.hits.hits[hit]["_source"]["app_name"])
    let  msgdate =msg.hits.hits[hit]["_source"]["@timestamp"]
    let date = new Date(msgdate)
    this.incomingMsgDates.push(date)

    //console.log(msg.hits.hits[hit]["_id"])
  }

  console.log(data)

},
error=>{
  console.log(error)
})   }

我在ngoninit()中调用此订阅方法:

toDate:Date = new Date()
  fromDate:Date = new Date(new Date().setDate(this.fromDate.getDate()-1)) //yesterday's date
this.getIncomingMessages(0, 10, this.fromDate.toISOString(),this.toDate.toISOString(), "desc"  )

有没有可能和认购承诺有关?这是我第一次与角和麋鹿工作,所以任何类型的指导将是有益的!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题