亲爱的圣诞老人,这里有一点小小的帮助,献给圣诞节

作者:来自 Elastic Laurent_Saint-Felix

每一年, Santa Claus 都会遇到同样的扩展性问题:数十亿的孩子,一个神奇的投递时间窗口,零容错空间

几个世纪以来,他一直用羊皮纸卷轴、羽毛笔,以及一个极度过度工作的精灵来运行一切。但今年, Santa 彻底现代化了他的 Naughty-and-Nice 运营技术栈。

  • 再见卷轴
  • 再见建立在希望和糖果拐杖之上的单体 North Pole 数据库。
  • 你好 Elasticsearch 。

而强大的集群,也带来了对......命令行的强烈需求。

幸运的是,精灵们在 GitHub 上发现了一个很有前途的 CLI ,并把它直接构建进了雪橇的车载计算机中: escli-rs

为什么 Santa 需要一个真正的 CLI

Kibana 仪表板很棒,除非你正以 Mach 8 的速度飞越 Tokyo ,而且真的不应该戴着厚重的手套去点击菜单按钮。

Santa 需要的是:

  • 快速
  • 可脚本化
  • 适合戴手套操作

于是 escli 登场了,这是一个 Elasticsearch CLI 的 概念验证 ,支持多个版本、安全认证、真正的 shell 自动补全,以及足够的便捷性来拯救圣诞节。

精灵们为 Santa 配置了他的 .env :

ini 复制代码
`

1.  ESCLI_URL=https://northpole.elasticsearch.cluster
2.  ESCLI_API_KEY=ho-ho-ho-secret

`AI写代码

一个充满孩子的 Cluster

现在已经建立了对 Cluster 的访问,精灵们开始向其中添加一些孩子。

bash 复制代码
`

1.  {"index": {"_index": "children-of-the-world", "_id": "zoe-8yo-france"}}
2.  {"name": "Zoe", "age": 8, "nice_score": 0.92, "gift_preference": "Lego Friends", "cookie_offerings": 5, "sibling_conflicts": 1}
3.  {"index": {"_index": "children-of-the-world", "_id": "jai-10yo-india"}}
4.  {"name": "Jai", "age": 10, "nice_score": 0.75, "gift_preference": "Cricket bat", "cookie_offerings": 2, "sibling_conflicts": 4}
5.  {"index": {"_index": "children-of-the-world", "_id": "mia-6yo-canada"}}
6.  {"name": "Mia", "age": 6, "nice_score": 0.98, "gift_preference": "Stuffed bear", "cookie_offerings": 10, "sibling_conflicts": 0}
7.  {"index": {"_index": "children-of-the-world", "_id": "lucas-11yo-usa"}}
8.  {"name": "Lucas", "age": 11, "nice_score": 0.33, "gift_preference": "RC car", "cookie_offerings": 1, "sibling_conflicts": 7}
9.  {"index": {"_index": "children-of-the-world", "_id": "sofia-9yo-spain"}}
10.  {"name": "Sofia", "age": 9, "nice_score": 0.87, "gift_preference": "Art supplies", "cookie_offerings": 4, "sibling_conflicts": 2}

`AI写代码![](https://csdnimg.cn/release/blogv2/dist/pc/img/runCode/icon-arrowwhite.png)
css 复制代码
`escli bulk --refresh wait_for --input children_of_the_world.ndjson`AI写代码

Santa 的 Elasticsearch 配置已经就绪,包含关键要素:

  • Index : children-of-the-world
  • Fields : name, age, nice_score, gift_preference, cookie_offerings, sibling_conflicts

现在,多亏了 escli , Santa 可以在地球上的任何地方查询它。甚至在飞行途中。

Santa 实际使用的真实命令

获取单个孩子的文档

arduino 复制代码
`escli get children-of-the-world "zoe-8yo-france"`AI写代码

搜索真正乖巧的孩子

vbnet 复制代码
`

1.  echo '{
2.    "query": {
3.      "range": {
4.        "nice_score": {"gte": 0.9}
5.      }
6.    }
7.  }' | escli search \
8.        --index children-of-the-world | jq

`AI写代码

将淘气名单导出为 CSV 文件

vbnet 复制代码
`

1.  echo '{
2.    "query": "FROM children-of-the-world | WHERE nice_score < 0.2"
3.  }' | escli esql query --format csv

`AI写代码

为了防止手动导出 Naughty List 打断他们的 December stand-up 会议,精灵们最终将这个过程自动化了。

幸运的是,今年名单是空的,因为每个人都很乖。

自动补全: Santa 的新宠功能

escli 中最酷的功能之一就是 shell 自动补全。

安装自动补全:

bash 复制代码
`eval "$(COMPLETE=bash ./escli)"`AI写代码

现在他可以输入:

bash 复制代码
`eval "$(COMPLETE=bash ./escli)"`AI写代码

然后他的终端会智能地补全为:

go 复制代码
`escli esql query`AI写代码

连驯鹿都印象深刻。

圣诞节被 --help 拯救

Santa 在庞大的物流网络中,需要记住几乎无限的 API 选项,有时会忘记一两个 flag 。他并不感到羞愧。他高兴地使用 --help flag 来快速回忆。

bash 复制代码
`escli --help`AI写代码
  • 有文档的命令。
  • 结构一致。
  • 没有意外。

精灵们甚至抵制住了添加 ASCII 艺术的冲动(在一次小小的 "terminal meltdown incident" 之后)。

Santa 滚动查看帮助输出,微笑着低声说:"这太有用了!" 并按时送出了数十亿份礼物。

如果它对 Santa 足够好......

......那么也许对你的 Elasticsearch cluster 也足够好了。

今天就从 escli-rs 仓库下载最新的预发布版本并尝试吧。

我们很想听到你的反馈:在 GitHub 上打开一个 issue,让我们知道你的想法!

原文:discuss.elastic.co/t/dec-1st-2...

相关推荐
vx-程序开发8 小时前
【计算机毕设】django校园跑腿服务系统83141
java·数据库·vue.js·spring boot·spring·elasticsearch·django
Elasticsearch10 小时前
jina-ocr-v1:在低成本 GPU 上实现更快速的文档解析
elasticsearch
深海鱼肝油ya11 小时前
向量数据库Elasticsearch(四)搜索文档——各种方式
人工智能·elasticsearch·向量数据库·es搜索文档·只能体·非结构化数据库
Elasticsearch15 小时前
SNAP 支付错误检测:Elastic 如何帮助美国各州应对 FY2028 的处罚
elasticsearch
Elastic 中国社区官方博客15 小时前
使用 Elasticsearch 和 Jina 进行 AI 视频搜索:精准找到你需要的视频片段秒数
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
Elasticsearch15 小时前
2026 年唯一获得满分 Endpoint Prevention and Response(EPR)评分的是 Elastic
elasticsearch
Elasticsearch2 天前
没有小到无法记录的日志文件:Elastic Agent 如何跟踪低于 1 KiB 阈值的文件
elasticsearch
Elasticsearch2 天前
使用 Elasticsearch 和 Jina 进行 AI 视频搜索:精准找到你需要的视频片段秒数
elasticsearch
Hrain-AI2 天前
AI 爬虫三档授权工程落地:搜索放行、训练拦截、Agent 分层(附脚本)
人工智能·elasticsearch·milvus
智搜广告2 天前
智搜广告:科技行业AI回答优化公司如何破局
大数据·python·elasticsearch·geo