I'm using Elasticsearch (with Tire) and need to create a facet which outputs a statistics about daily unique mac addresses per day, week, month. I've been running into problems getting it working correctly.

I need to mean and total figures and couldn't get it working with the date\_histogram facet:

```
def self.search_stats params
  tire.search(page: params[:page], per_page: 50) do |s|
    filter = []
    filter << { :terms => { ... }}

    s.facet('uniques') do
      date :created_at, :interval => 'day', value_field: 'mac.sortable'
      facet_filter :and, filter
    end
  end
end

```

That gave an error: "Failed to parse source... "

In the end, I've been trying to use a script to get it done but that's not really working out as I can't figure out how to group the values.

I been using:

```
date :created_at, value_script: "doc['mac.sortable'].values.size()", interval: 'day'

```

Obvs. size() is wrong as I need the unique values.

My mapping looks like this:

```
mapping do
  ...
  indexes :mac, type: 'multi_field', fields: {
    raw: {type: 'string', index: 'analyzed'},
    sortable: {type: 'string', index: :not_analyzed}
  }
  ...
end

```

I don't really want to use a script field at all because of the memory usage warning.

How can I get my macs grouped and sorted daily?