Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
666 views
in Technique[技术] by (71.8m points)

will elasticsearch date_histogram check the date inside the interval exist or not? And if so , what will happen? If no any error handling for this

So far i am working on the ES date histogram for getting monthly result, and my query is like

{
  "aggs": {
    "sales_over_time": {
      "date_histogram": {
        "field": "date",
                "calendar_interval": "1M",
                "offset":    Cutoff          

      }
    }
  }
}

and the return is like

                  date
1             10978.521    2020-11-20    5995.69  
2             11177.911    2020-12-20     199.39  
3             11177.911    2021-01-20       0.00  

So my question is : what if the date "20" is not exist ? and any error handling from ES? thanks

Jeff

question from:https://stackoverflow.com/questions/65931478/will-elasticsearch-date-histogram-check-the-date-inside-the-interval-exist-or-no

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Since it's a monthly date histogram, each bucket must have a date key. That date key is the date of the beginning of the monthly bucket. For instance, 2020-11-20 is the key and the starting date of the bucket starting on that date. In that bucket, you will find all documents whose date is between 2020-11-20 and 2020-12-20.

Same thing for the last bucket which starts on 2021-01-20, it will contain all documents starting on that date and going through 2021-02-20. It doesn't matter whether you have documents whose date field is specifically on those bucket key dates, those keys are just interval bounds.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...