date(field, options={})
click to toggle source
def date(field, options={})
interval = { :interval => options.delete(:interval) || 'day' }
fields = options[:value_field] || options[:value_script] ? { :key_field => field } : { :field => field }
@value[:date_histogram] = {}.update(fields).update(interval).update(options)
self
end
facet_filter(type, *options)
click to toggle source
def facet_filter(type, *options)
@value[:facet_filter] = Filter.new(type, *options).to_hash
self
end
filter(type, options={})
click to toggle source
def filter(type, options={})
@value[:filter] = Filter.new(type, options)
self
end
geo_distance(field, point, ranges=[], options={})
click to toggle source
def geo_distance(field, point, ranges=[], options={})
@value[:geo_distance] = { field => point, :ranges => ranges }.update(options)
self
end
histogram(field, options={})
click to toggle source
def histogram(field, options={})
@value[:histogram] = (options.delete(:histogram) || {:field => field}.update(options))
self
end
query(&block)
click to toggle source
def query(&block)
@value[:query] = Query.new(&block).to_hash
end
range(field, ranges=[], options={})
click to toggle source
def range(field, ranges=[], options={})
@value[:range] = { :field => field, :ranges => ranges }.update(options)
self
end
statistical(field, options={})
click to toggle source
def statistical(field, options={})
@value[:statistical] = (options.delete(:statistical) || {:field => field}.update(options))
self
end
terms(field, options={})
click to toggle source
def terms(field, options={})
size = options.delete(:size) || 10
all_terms = options.delete(:all_terms) || false
@value[:terms] = if field.is_a?(Enumerable) and not field.is_a?(String)
{ :fields => field }.update({ :size => size, :all_terms => all_terms }).update(options)
else
{ :field => field }.update({ :size => size, :all_terms => all_terms }).update(options)
end
self
end
terms_stats(key_field, value_field, options={})
click to toggle source
def terms_stats(key_field, value_field, options={})
@value[:terms_stats] = {:key_field => key_field, :value_field => value_field}.update(options)
self
end
to_hash()
click to toggle source
def to_hash
@value.update @options
{ @name => @value }
end
to_json(options={})
click to toggle source
def to_json(options={})
to_hash.to_json
end