title: Combining Range and Histogram Filter in ElasticSearch
body: <p>Consider an event log stored in ElasticSearch. Events look like this</p>
  
  <pre><code>{
    "timestamp": "2013-04-04T15:38:17Z",
    "color": "red"
  }
  
  {
    "timestamp": "2013-04-04T17:51:21Z",
    "color": "green"
  }
  </code></pre>
  
  <p>I want to draw frequency timelines per color. I know that I can get the timelines with two queries like this:</p>
  
  <pre><code>{
    "query": {
      "match": {
        "color": "red"
      }
    },
    "size": 0,
    "facets": {
      "freq": {
        "date_histogram": {
          "interval": "day",
          "field": "timestamp"
        }
      }
    }
  }
  </code></pre>
  
  <p>The second query would <code>"match": { "color": "green" }</code>.</p>
  
  <p>Can I combine these queries into one, that gives my either</p>
  
  <ul>
  <li>count(color) / day / bucket</li>
  <li>or one facet per color, containing the histogram for that color?</li>
  </ul>
  
  <p>For two colors separate queries could work just fine, but as you might suspect this is a contrieved example. I am really dealing with more than ten colors and at this point a single query would be really nice.</p>