elassandra中的日期范围搜索

wvt8vs2t  于 2021-06-15  发布在  Cassandra
关注(0)|答案(1)|浏览(374)

我创建了一个索引,如下所示。

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+0000”,“to”:“2039-05-07 11:22: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

请告知。

trnvg8h3

trnvg8h31#

查询的格式似乎不正确。请参阅上的日期范围聚合文档https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html 注意区别:
你在引入一个没有定义任何查询的查询-你需要一个吗?
你应该使用聚合而不是聚合
你应该命名你的聚合

相关问题