ElasricSearch两个字段相加报错

简介: ElasricSearch两个字段相加报错

问题背景:

ES两个字段相加的查询报错:unsupported_operation_exception

{
"error":{
"root_cause":[
            {
"type":"unsupported_operation_exception",
"reason":"scripts of type [inline], operation [update] and lang [expression] are not supported"            }
        ],
"type":"unsupported_operation_exception",
"reason":"scripts of type [inline], operation [update] and lang [expression] are not supported"    },
"status":500}


问题原因:

脚本语法问题


解决方案

1、创建索引

PUT test3
{
  "mappings" : {
      "properties" : {
        "a1" : {
          "type" : "long"
        },
        "b1" : {
          "type" : "long"
        },
        "date1" : {
          "type" : "date"
        }
      }
    }
}


2、put数据

POST test3/_doc/001
{
 "a1":22,"b1":33
}


3、查询

GET test3/_search
{
    "from":0,
    "size":1,
    "query":{
        "match":{
            "a1":"22"
        }
    },
    "sort":{
        "a1":"desc"
    },
    "_source":{
        "includes":[
            "a1",
            "b1"
        ]
    },
    "script_fields":{
        "c1":{
            "script":{
                "lang":"expression",
                "source":"doc['a1'] + doc['b1']"
            }
        }
    }
}


适用范围

检索分析服务Elasticsearch版

相关文章
|
Linux 网络安全
linux避免ssh远程超时断开
linux避免ssh远程超时断开
linux避免ssh远程超时断开
|
Ubuntu Linux
Centos or Ubuntu 重新安装network服务
Centos or Ubuntu 重新安装network服务
|
SQL 前端开发 API
SqlAlchemy 2.0 中文文档(二十七)(1)
SqlAlchemy 2.0 中文文档(二十七)
248 1
|
12月前
|
SQL 安全 网络安全
网络安全漏洞、加密技术与安全意识的知识分享
随着互联网的普及,网络安全问题日益严重。本文将介绍网络安全漏洞的概念、类型和防范措施,以及加密技术的原理和应用。同时,强调提高个人和企业的安全意识对于防范网络攻击的重要性。
358 7
|
前端开发 Java Linux
|
Oracle Ubuntu 安全
linux系统构建持续集成环境(jenkins)
linux系统构建持续集成环境(jenkins)
|
SQL 分布式计算 DataWorks
MaxCompute-Java自建UDF入门详解
MaxCompute-Java自建UDF入门详解
|
Unix
FreeBSD 11.4 系统磁盘管理
freeBSD系统没有fdisk等命令,是使用 gpart 命令管理磁盘信息
741 0
FreeBSD 11.4 系统磁盘管理
|
自然语言处理 Java 开发工具
ES上传自编译IK分词插件
ES上传自编译IK分词插件
ES上传自编译IK分词插件