The requested URL was not found on this server. 不管你信不信,反正我是没找到

关于ES script使用中百思不得其解的问题

Elasticsearch | 作者 nanguadada | 发布于2019年05月08日 | 阅读数:5534

在项目中有个需求是判断第14位为5,因此用script来解决,当然  大于等于14位已先判断在ES中 同一个script换一个方式就会报错,
第一种  (报错)
   {
          "script": {
            "script": "doc['cm_tx_log_no'].value.indexOf(53, 14)==14"
          }
    }
 第二种 (不报错)
    {
          "script": {
            "script": "doc['cm_tx_log_no'].value.indexOf('5', 14)==14"
          }
    }
报错信息:
    "script": "doc['cm_tx_log_no'].value.indexOf(53, 14)==14",
          "lang": "painless",
          "caused_by": {
            "type": "wrong_method_type_exception",
            "reason": "cannot convert MethodHandle(String,String,int)int to (Object,int,int)Object"
          }
 
关键是
53和'5'  不是一样的吗,String.indexOf  也支持数值类型参数,在IDEA中测试不报错,不懂他为什么一直要转换类型。   有没有大神帮忙解惑一下。 
已邀请:

rochy - rochy_he

赞同来自:

53 和'5'  当然不是一样的
53 是 int 类型, '5' 是 string 类型

要回复问题请先登录注册