问题背景:
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版