Home How to filter the documents based on created_date in elasticsearch index?
Reply: 0

How to filter the documents based on created_date in elasticsearch index?

user3106940
1#
user3106940 Published in 2018-02-06 07:18:38Z

I need to get the documents which are created today

Say A is my model, following is the mapping and indexed columns

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

I could get the documents within the date range using range filter and 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"]]}

However, not being able to find a filter which will match documents with todays dat

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.293344 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO