您现在的位置是:首页 > 文章详情

elasticsearch-script-velocity 8.11.0-1.0.0 发布

日期:2023-11-20点击:282

License GitHub release codecov Integration Test Status

Search Template  Elasticsearch 中一项非常实用的功能。通过这一特性,搜索请求的查询结构可以事先定义好,然后在实际请求时传入搜索参数。这样既使得请求体更加简洁,也避免了在客户端拼接查询结构时可能出现的错误。

在需要进行搜索调优时,可以直接在 Elasticsearch 服务端修改搜索脚本,而无需重新发布客户端。这显著提高了搜索调优的效率。

然而,Elasticsearch 默认支持的脚本语言mustache/painless/expression)的语法逻辑相对较为有限,不支持逻辑判断,从而对 Search Template 的使用带来了一定的限制。

通过引入 Velocity  Elasticsearch 中,可以支持任何逻辑判断,使得 Search Template 的使用更加灵活。这为用户提供了更强大、更灵活的搜索定制能力。

更新内容 🎉 🎉 🎉

支持 ElasticSearch v8.11.0 版本

  • 依赖: 更新 elasticsearch 版本 v8.11.0
  • 测试: 提升单元测试覆盖率
  • 测试: 添加JMH基准测试
  • 重构:修改版本号发布策略(version=elasticsearchVersion-pluginVersion

安装

方式 1 - 使用 elasticsearch-plugin  安装

 ./bin/elasticsearch-plugin install https://github.com/Ahoo-Wang/elasticsearch-script-velocity/releases/download/v8.11.0/elasticsearch-script-velocity-8.11.0.zip 

方式 2 - 从 Releases 下载构建包

  1. 创建插件目录 cd your-es-root/plugins/ && mkdir elasticsearch-script-velocity
  2. 解压到该目录 your-es-root/plugins/elasticsearch-script-velocity

使用

存储脚本

create-stored-script-api

 POST _scripts/templateid { "script": { "lang": "velocity", "source": { "query": { "match": { "title": "$query_string" } } } } }

获取已存储的脚本

get-stored-script-api

 GET _scripts/templateid

请求响应结果:

 { "_id": "templateid", "found": true, "script": { "lang": "velocity", "source": """{"query":{"match":{"title":"$query_string"}}}""", "options": { "content_type": "application/json;charset=utf-8" } } }

删除已存储的脚本

delete-stored-script-api

 DELETE _scripts/templateid

模板搜索

search-template

 GET _search/template { "id": "templateid", "params": { "query_string": "search for these words" } }

验证搜索模板

 GET _render/template/templateid { "params": { "query_string": "search for these words" } }

请求响应结果:

 { "template_output": { "query": { "match": { "title": "search for these words" } } } } 
原文链接:https://www.oschina.net/news/267278
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章