【问题标题】:Date range search in ElassandraElassandra中的日期范围搜索
【发布时间】:2018-10-31 15:36:09
【问题描述】:

我创建了如下索引。

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

请指教。

【问题讨论】:

    标签: elasticsearch cassandra elassandra


    【解决方案1】:

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

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

    【讨论】:

    • 我是新手,我按照你说的尝试了,但我得到了不同的结果。我的意思也是其他年份的值。 curl -XGET -H 'Content-Type: application/json' '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”,“范围”:[{“到”:“2039-05-07 11:22:34+0000”},{“从”:“2039-05-07 11:22:34+0000"} ] } } } }' 另外,从您分享的链接来看,“from”似乎包含但不包含“to”。
    • 抱歉,我不明白你的问题是什么。请进一步详述。谢谢!
    • 从上面 cmets 中的 curl 语句,当我尝试获取日期范围为 2039-05-07 11:22:34+0000 到 2039-05-07 11:22 的结果时: 34+0000,我得到 2024...,2010.... 的结果,这不是我想要获取的范围。我的 curl 语句在 cmets 中是否正确,如果可能的话,您能否提供一个场景示例以获取搜索结果。
    • 好的,所以你最初的问题现在已经解决了(查询时出错)。很高兴这对您有用,我们在这里有答案!您介意为聚合范围主题打开一个新问题吗?这将有助于其他人也在寻找关于这两个主题的解决方案。随时在此处链接新问题。
    • 好的,谢谢。现在我问了其他问题,我得到了不同的搜索结果。 link
    猜你喜欢
    • 1970-01-01
    • 2019-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-01
    相关资源
    最近更新 更多