0

I have created a index like below.

curl -XPUT -H 'Content-Type: application/json' 'http://x.x.x.x:9200/date_index' -d '{
  "settings" : { "keyspace" : "keyspace1"},
  "mappings" : {
    "table1" : {
      "discover":"sent_date",
      "properties" : {
        "sent_date" : { "type": "date", "format": "yyyy-MM-dd HH:mm:ssZZ" }
        }
    }
  }
}'

I need to search the results pertaining to date range, example "from" : "2039-05-07 11:22:34+0000", "to" : "2039-05-07 11:22:34+0000" both inclusive. I am trying like this,

curl -XGET -H 'Content-Type: application/json' 'http://x.x.x.x:9200/date_index/_search?pretty=true' -d '
{
  "query" : {
    "aggregations" : {

    "date_range" : {
      "sent_date" : {
        "from" : "2039-05-07 11:22:34+0000",
        "to" : "2039-05-07 11:22:34+0000"
        }
      }
    }

  }
}'

I am getting error as below.

  "error" : {
    "root_cause" : [
      {
        "type" : "parsing_exception",
        "reason" : "no [query] registered for [aggregations]",
        "line" : 4,
        "col" : 22
      }
    ],
    "type" : "parsing_exception",
    "reason" : "no [query] registered for [aggregations]",
    "line" : 4,
    "col" : 22
  },
  "status" : 400

Please advise.

Pramod
  • 113
  • 2
  • 14

1 Answers1

0

The query seems to be malformed. Please see the date range aggregation documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html and note the differences:

  • you're introducing a query without defining any - do you need one?
  • you should use aggs instead of aggregations
  • you should name your aggregation
ibexit
  • 3,465
  • 1
  • 11
  • 25
  • I am newbie, I tried as you said but i am getting different results. I mean other year values also. curl -XGET -H 'Content-Type: application/json' 'http://x.x.x.x:9200/date_index/_search?pretty=true' -d ' { "aggs" : { "sentdate_range_search" : { "date_range" : { "field" : "sent_date", "format" : "yyyy-MM-dd HH:mm:ssZZ", "ranges" : [ { "to" : "2039-05-07 11:22:34+0000"}, { "from" : "2039-05-07 11:22:34+0000"} ] } } } }' Also, from the link you shared, seems like "from" is inclusive but not "to". – Pramod Nov 01 '18 at 18:12
  • Sorry, but I'm not getting what your question is. Please elaborate further. Thx! – ibexit Nov 01 '18 at 21:33
  • From the above curl statement in the comments, when i try to fetch the results with the date range 2039-05-07 11:22:34+0000 to 2039-05-07 11:22:34+0000, I am getting results of 2024...,2010.... which were not the range that i want to fetch. Is my curl statement correct or not that was in comments, if possible can you provide an example of the scenario to get search result. – Pramod Nov 01 '18 at 21:52
  • Ok, so your initial problem is solved now (error when quering). Glad that this worked for you and we have a answer here! Would you mind to open a new question for the aggregation range topic? This will help other too searching SO for a solution on both topics. Feel free to link the new question here. – ibexit Nov 02 '18 at 06:51
  • yes, thanks. Now i requested other question where i am getting different search results. [link](https://stackoverflow.com/questions/53120844/aggregation-date-range-query-in-elassandra-elastic-search) – Pramod Nov 02 '18 at 14:53