Elassandra中的日期范围搜索



我创建了一个如下的索引。

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" }
}
}
}
}'

我需要搜索与日期范围有关的结果,例如"from":"2039-05-07 11:22:34+000","to":"2029-05-07 11:0022:34+0000",包括两者。我正试着这样,

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"
}
}
}
}
}'

我收到错误,如下所示。

"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

请告知。

查询的格式似乎不正确。请参阅上的日期范围聚合文档https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html并注意差异:

  • 您引入了一个没有定义任何查询的查询-您需要一个吗
  • 应该使用aggs而不是聚合
  • 你应该命名你的聚合

最新更新