ElasticSearch bool查询日期范围

时间:2018-10-31 04:26:07

标签: apache-spark elasticsearch

我是ElasticSearch的新手,正在寻找bool查询以将其传递给Spark Scala代码中的Elasticsearch获取数据。

这是我的查询:

获取eventName =“ XXXXXX”和日期之间的所有记录(“ 1438367180542”,“ 1738367180542”)

您能帮我写Elasticsearch查询吗?下面是我尝试过的方法,但是它给出了错误。

GET _search
{
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "date": {
              "gte": "1438367180542",
              "lte": "1738367180542"
            }
            }
        }
      ],

          "term": {
              "eventName.keyword": "XXXXXXX"
          }
    }
  }
}

这是错误消息:

{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "[bool] query does not support [term]",
        "line": 15,
        "col": 19
      }
    ],
    "type": "parsing_exception",
    "reason": "[bool] query does not support [term]",
    "line": 15,
    "col": 19
  },
  "status": 400
}

1 个答案:

答案 0 :(得分:1)

您快到了!如您所见,您的[myView.layer removeAllAnimations]; 查询被花括号包围,但是您的range查询不是并且不在term数组之内。只需添加这些内容并将其移至must数组即可。最好使用must而不是filter,因为您只有过滤条件(也就是说,您不希望在此处评分)

must