Search code examples
elasticsearchcassandraelassandra

Date range search in Elassandra


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.


Solution

  • 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