试试搜索一下吧

Filter中term和range不能同时用么?

Elasticsearch | 作者 tc | 发布于2018年05月22日 | 阅读数:16701

有两个filter条件,应该怎么写?
 
GET test/_search
{
  "query": {
    "bool": {
      "filter": {
        "term": {
          "name": "kevin"
        },
        "range": {
          "age": {
            "gte": 20,
            "lte": 30
          }
        }
      }
    }
  }
}
 
会报错:
{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "[term] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
        "line": 8,
        "col": 9
      }
    ],
    "type": "parsing_exception",
    "reason": "[term] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
    "line": 8,
    "col": 9
  },
  "status": 400
}
已邀请:

strglee

赞同来自: create17

{
"query": {
"bool": {
"filter": [
{
"term": {
"name": "kevin"
}
},
{
"range": {
"age": {
"gte": 20,
"lte": 30
}
}
}
]
}
}
}

要回复问题请先登录注册