看,灰机...

es script查询报错

Elasticsearch | 作者 qq1201168 | 发布于2019年10月17日 | 阅读数:5602

这是我的es语句
POST xxx/_search
{
  "size":100,
    "query": {
        "bool" : {
            "must" : [
              {
                "script" : {
                    "script" : {
                        "inline": "doc['createTime'].getDate().getMonthOfYear() == 11",
                        "lang": "painless"
                    }
                }
            }
            ]
        }
    }
}
查询的时候报如下错误
{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "runtime error",
        "script_stack": [
          "doc['createTime'].getDate().getMonthOfYear() == 11",
          "                 ^---- HERE"
        ],
        "script": "doc['createTime'].getDate().getMonthOfYear() == 11",
        "lang": "painless"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "yimi_crm_label_info",
        "node": "YXl5mywNT9yX3SrXMK2BsA",
        "reason": {
          "type": "script_exception",
          "reason": "runtime error",
          "script_stack": [
            "doc['createTime'].getDate().getMonthOfYear() == 11",
            "                 ^---- HERE"
          ],
          "script": "doc['createTime'].getDate().getMonthOfYear() == 11",
          "lang": "painless",
          "caused_by": {
            "type": "illegal_argument_exception",
            "reason": "dynamic method [org.elasticsearch.index.fielddata.ScriptDocValues.Dates, getDate/0] not found"
          }
        }
      }
    ]
  },
  "status": 400
}
createTime是date类型。看了很多技术文档都是这样写的,不知道我这里哪里有问题。还请大佬指教
已邀请:

fish_to_sky

赞同来自:

同问

core_wzw - 某AILab搜索技术负责人

赞同来自:

看报错,要不你的ES版本太低,要不就是有的文档createTime字段没值。
https://elasticsearch.cn/question/3649

mobikarl

赞同来自:

这样写
 
GET kibana_sample_data_ecommerce/_search
{
  "size": 100,
  "query": {
    "bool": {
      "must": [
        {
          "script": {
            "script": {
              "source": "doc['order_date'].value.getMonthValue()==11",
              "lang": "painless"
            }
          }
        }
      ]
    }
  }
}

要回复问题请先登录注册