title: Build a Kibana Histogram with buckets dynamically created by ElasticSearch terms aggregation
body: <p>I want to be able to combine the functionality of the <em>Kibana</em> <strong>Terms Graph</strong> (be able to create buckets based on uniqueness of values from a particular attribute) and <strong>Histogram Graph</strong> (separate data into buckets based on queries and then illustrate the date based on time).</p>
  
  <p>Overall, I want to create a Histogram, but I only want to create the Histogram based on the results of one query, not multiple queries like it's being done in the <a href="http://demo.kibana.org/#/dashboard" rel="nofollow noreferrer">Kibana demo app</a>. Instead, I want each bucket to be dynamically created per unique value of my particular field. For example, consider the following data returned by my query:</p>
  
  <pre><code>{"myValueType": "New York"}
  {"myValueType": "New York"}
  {"myValueType": "New York"}
  {"myValueType": "San Francisco"}
  {"myValueType": "San Francisco"}
  </code></pre>
  
  <p>Also assume that each record has a <code>timestamp</code> field for separating histogram data by date. For that particular date, I want the data to be communicated as a count of 3 into the <code>New York</code> bucket and a count of 2 into the <code>San Francisco</code> bucket. However, I am only able to show a count of 5 for my one linked query. When I configure the Histogram, I am able to specify a field to use for my timestamp, but not to create buckets from. I could've sent a field to compute a total/min/max/mean, but this field would've had to be numeric, so that is not the solution either.</p>
  
  <p>If I were to use a Term Graph to create a pie or bar graph, I am indeed able to separate my data into buckets based on the unique values of my specified field (in this case, "myValueType"), but this would total up the data for all-time, not split up the data by timestamp. Although this is good information to know, it is not ideal because I wouldn't be able to detect trends in my data.</p>
  
  <p>I am looking for a solution that will do one of the following:</p>
  
  <ul>
  <li>Let me dynamically create queries in my Kibana dash board to create "buckets" in a Histogram</li>
  <li>Allow me to run an <a href="http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/search-aggregations-bucket-terms-aggregation.html" rel="nofollow noreferrer">ElasticSearch Terms Aggregation</a> to <em>supposidly</em> split up my data into buckets based on "myValueType" and integrate these results into my Histogram</li>
  <li>Customize the JSON of my dashboard, but this doesn't look possible to me</li>
  <li>Create my own custom panel, but this is not desirable</li>
  <li>Link a Kibana "TopN" query in Kibana. Actually, this has proven to be a work-around for my problem because the TopN query dynamically created one query per unique value/term from the specified fieldName. However, the problem is that I can only link one colour to this TopN query and each unique term will be placed in a bucket that uses a different shade of the colour. Ideally, every bucket in my Histogram will have a completely different colour associated to it. Imagine how difficult it will be to distinguish unique terms as the number of buckets grows.</li>
  <li>If all else fails, I make one query per unique value from my search field. This will allow me to have one unique colour per bucket, but as the number of unique terms in the "myValueType" field changes, I need to keep adding/removing queries from Kibana, which can get quite messy.</li>
  </ul>
  
  <p>I'm sure there is someting that I am missing here. Please help me out. Many thanks.</p>
  
  <p>A highly related SOF question: <a href="https://stackoverflow.com/questions/18986803/is-it-possible-to-use-histogram-facet-or-its-curl-response-in-kibana">Is it Possible to Use Histogram Facet or Its Curl Response in Kibana</a></p>