title: How to group documents by hour without day in elasticsearch?
body: <p>i have a application who a survey is asked every day by users, and i want to have average answers hours. I tried some request but i can't group all documents by hours, it's grouped by hour by day..</p>
  
  <p>I do this : </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>{
   "aggs": {
        "byHour": {
            "date_histogram": {
                "field": "date",
                "interval": "hour",
                "format" : "H"
  
                  }
              }
          }
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>It's wrapped by hour but also by date, and i want <code>day</code> as ignored.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> [
          {
            "key_as_string": "0",
            "key": 1533945600000,
            "doc_count": 40,
            "group_by_state": {
              "doc_count_error_upper_bound": 0,
              "sum_other_doc_count": 0,
              "buckets": []
            }
          },
          {
            "key_as_string": "1",
            "key": 1533949200000,
            "doc_count": 345,
            "group_by_state": {
              "doc_count_error_upper_bound": 0,
              "sum_other_doc_count": 0,
              "buckets": []
            }
          },
          {
            "key_as_string": "23",
            "key": 1534028400000,
            "doc_count": 15,
            "group_by_state": {
              "doc_count_error_upper_bound": 0,
              "sum_other_doc_count": 0,
              "buckets": []
            }
          },
          {
            "key_as_string": "0",
            "key": 1534032000000,
            "doc_count": 0,
            "group_by_state": {
              "doc_count_error_upper_bound": 0,
              "sum_other_doc_count": 0,
              "buckets": []
            }
          },
          {
            "key_as_string": "1",
            "key": 1534035600000,
            "doc_count": 2,
            "group_by_state": {
              "doc_count_error_upper_bound": 0,
              "sum_other_doc_count": 0,
              "buckets": []
            }
          },
          {
            "key_as_string": "2",
            "key": 1534039200000,
            "doc_count": 3,
            "group_by_state": {
              "doc_count_error_upper_bound": 0,
              "sum_other_doc_count": 0,
              "buckets": []
            }
          }
   ]</code></pre>
  </div>
  </div>
  </p>
  
  <p>Mapping of type </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>{
    "myIndex": {
      "mappings": {
        "answer": {
          "properties": {
            "date": {
              "type": "date"
            },
            "lang": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "level": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "offset": {
              "type": "long"
            },
            "patientCaretrackId": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "protocolId": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "query": {
              "properties": {
                "constant_score": {
                  "properties": {
                    "filter": {
                      "properties": {
                        "bool": {
                          "properties": {
                            "must": {
                              "properties": {
                                "term": {
                                  "properties": {
                                    "questionId": {
                                      "type": "text",
                                      "fields": {
                                        "keyword": {
                                          "type": "keyword",
                                          "ignore_above": 256
                                        }
                                      }
                                    },
                                    "questionnaireId": {
                                      "type": "text",
                                      "fields": {
                                        "keyword": {
                                          "type": "keyword",
                                          "ignore_above": 256
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            },
            "questionId": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "questionnaireId": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "surgeonId": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "value": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              },
              "fielddata": true
            }
          }
        }
      }
    }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Example of documents : </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>[
  {
            "date": "2018-09-11T00:00:00.000Z",
            "lang": "fr",
            "level": "red",
            "offset": 21,
            "patientCaretrackId": "5b894b10a9f7afec73762113",
            "protocolId": "ptg-koos-long-v1",
            "questionnaireId": "j21",
            "surgeonId": "699362de-f040-4799-b1ea-53f5b4a2fe03",
            "value": "permanentes",
            "questionId": "frequence-douleur-2"
  },
  {
            "date": "2018-09-11T00:00:00.000Z",
            "lang": "fr",
            "level": "red",
            "offset": 21,
            "patientCaretrackId": "5b894b10a9f7afec73762113",
            "protocolId": "ptg-koos-long-v1",
            "questionnaireId": "j21",
            "surgeonId": "699362de-f040-4799-b1ea-53f5b4a2fe03",
            "value": "permanentes",
            "questionId": "frequence-douleur-2"
          }
  ]</code></pre>
  </div>
  </div>
  </p>
  
  <p>It's possible to do this with an query Elasticsearch ? </p>
  
  <p>Thank you,</p>