我需要获取今天创建的文档
说A是我的模型,以下是映射和索引列
def as_indexed_json(options={})
self.as_json({only: [:id,:user_id,:user_agent, :browser,:created_at]})
end
settings :index => { :number_of_shards => 1 } do
mapping :dynamic => 'false' do
indexes :id, :type => 'integer'
indexes :user_agent, :type => 'string'
indexes :created_at, :type => 'date',:format => "dd/MM/yyyy"
end
end
我可以使用范围过滤器和elasticrange-model gem获取日期范围内的文档。
query = "{\"query\": {\"range\" : {\"created_at\" : {\"gte\": \"05/01/2018\", \"lte\": \"05/02/2018\", \"format\": \"dd/MM/yyyy||dd/MM/yyyy\"} } },\"aggs\": {\"group_by_browser\": {\"terms\": {\"field\": \"browser\"} } } }"
response = A.__elasticsearch__.search query
response.response["aggregations"]["group_by_browser"]["buckets"].map{|k| [k["key"],k["doc_count"]]}
但是,无法找到与今日数据文档匹配的过滤器