疲劳是最舒适的枕头,努力工作吧。

elasticsearch如何使用script(python)的复杂语句?

Elasticsearch | 作者 xiajichenxi | 发布于2021年07月02日 | 阅读数:4103

版本:5.4.1
 
问题描述:
测试一:简单的替换值
{
"query": {
"terms": {
"objectid.keyword": [
"81FB61F1-B45E-4180-8336-D8D2B6DF6827",
"DD5C98E4-629F-4F63-99C3-86841C8DBEF1",
"DD7E8F66-6473-4DCF-B84F-4B85299EE6DD"
]
}
},
"script": {
"lang": "python",
"inline": "ctx['_source']['system_version'] = 'aczxczxc'"

}
}

测试二:替换array中第一个元素的key对应的value
{
"query": {
"terms": {
"objectid.keyword": [
"81FB61F1-B45E-4180-8336-D8D2B6DF6827",
"DD5C98E4-629F-4F63-99C3-86841C8DBEF1",
"DD7E8F66-6473-4DCF-B84F-4B85299EE6DD"
]
}
},
"script": {
"lang": "python",
"inline": "i = ctx['_source']['city_info'][0];i['permanent_country'] = i['isp']"
}
}

 像上面测试一、测试二这种的替操作换是没有任何问题的,测试都能成功。
但是如果使用for循环的话,就直接报错了,感觉还是语法问题,但是网上能找到的资料是在太少了:
测试三:
{
"query": {
"terms": {
"objectid.keyword": [
"81FB61F1-B45E-4180-8336-D8D2B6DF6827",
"DD5C98E4-629F-4F63-99C3-86841C8DBEF1",
"DD7E8F66-6473-4DCF-B84F-4B85299EE6DD"
]
}
},
"script": {
"lang": "python",
"inline": "for i in [1,2]:;print(i)"
}
}
{
"query": {
"terms": {
"objectid.keyword": [
"81FB61F1-B45E-4180-8336-D8D2B6DF6827",
"DD5C98E4-629F-4F63-99C3-86841C8DBEF1",
"DD7E8F66-6473-4DCF-B84F-4B85299EE6DD"
]
}
},
"script": {
"lang": "python",
"inline": "for i in ctx['_source']['city_info'];i['permanent_country'] = i['isp']"
}
}
这种for都不行。api除了返回“py_syntax_error”没有更多提示信息
已邀请:

Ombres

赞同来自: xiajichenxi

语法有问题
for i in [1,2]:print(i)

Charele - Cisco4321

赞同来自:

第一次见到,这里面也能用python,
 
用plainless不香吗?

Charele - Cisco4321

赞同来自:

我试了下,它报
"script_lang not supported [python]",
是要装什么插件吗?还是说新版的ES不支持这个了,

要回复问题请先登录注册