Painless 脚本中ctx 和 doc,params._source到底有啥区别?

本文详细介绍了Elasticsearch的Painless脚本在不同场景下使用ctx、doc、_source的区别。通过案例分析了ingest管道、update/update_by_query、reindex和search脚本中的应用,并提供了获取字符串子串和日期年份的脚本示例。文章总结了各种场景下选择ctx、doc、_source的依据,帮助读者更好地理解Painless脚本实战。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

es_search_in_server({'size': 10000, '_source': ['file_name'], 'query': {'bool': {'should': [{'match': {'recall_text': {'query': '幻方量化'}}}], 'filter': [{'script': {'script': {'source': "doc['recall_text.keyword'].value.length() < 5000","lang": "painless"}}}]}}}) 2025-06-13 11:39:08,871 - INFO - elastic_transport.transport - POST http://101.71.15.246:39200/hx_v3_04221821/_search [status:400 duration:0.075s] Traceback (most recent call last): File "/Applications/PyCharm.app/Contents/plugins/python/helpers-pro/pydevd_asyncio/pydevd_asyncio_utils.py", line 117, in _exec_async_code result = func() ^^^^^^ File "<input>", line 1, in <module> File "/Users/a123/Desktop/easyLink-code/xinai/rag_recall/search/tools.py", line 31, in es_search_in_server res = es_client.search(index=index_name, body=query) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/envs/env1/lib/python3.12/site-packages/elasticsearch/_sync/client/utils.py", line 455, in wrapped return api(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/envs/env1/lib/python3.12/site-packages/elasticsearch/_sync/client/__init__.py", line 5061, in search return self.perform_request( # type: ignore[return-value] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/envs/env1/lib/python3.12/site-packages/elasticsearch/_sync/client/_base.py", line 271, in perform_request response = self._perform_request( ^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/envs/env1/lib/python3.12/site-packages/elasticsearch/_sync/client/_base.py", line 352, in _perform_request raise HTTP_EXCEPTIONS.get(meta.status, ApiError)( elasticsearch.BadRequestError: BadRequestError(400, 'search_phase_execution_exception', 'runtime error') 还是报错
最新发布
06-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

少林码僧

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值