作者:来自 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 :
ESCLI_URL=https://northpole.elasticsearch.cluster
ESCLI_API_KEY=ho-ho-ho-secret
一个充满孩子的 Cluster
现在已经建立了对 Cluster 的访问,精灵们开始向其中添加一些孩子。
{"index": {"_index": "children-of-the-world", "_id": "zoe-8yo-france"}}
{"name": "Zoe", "age": 8, "nice_score": 0.92, "gift_preference": "Lego Friends", "cookie_offerings": 5, "sibling_conflicts": 1}
{"index": {"_index": "children-of-the-world", "_id": "jai-10yo-india"}}
{"name": "Jai", "age": 10, "nice_score": 0.75, "gift_preference": "Cricket bat", "cookie_offerings": 2, "sibling_conflicts": 4}
{"index": {"_index": "children-of-the-world", "_id": "mia-6yo-canada"}}
{"name": "Mia", "age": 6, "nice_score": 0.98, "gift_preference": "Stuffed bear", "cookie_offerings": 10, "sibling_conflicts": 0}
{"index": {"_index": "children-of-the-world", "_id": "lucas-11yo-usa"}}
{"name": "Lucas", "age": 11, "nice_score": 0.33, "gift_preference": "RC car", "cookie_offerings": 1, "sibling_conflicts": 7}
{"index": {"_index": "children-of-the-world", "_id": "sofia-9yo-spain"}}
{"name": "Sofia", "age": 9, "nice_score": 0.87, "gift_preference": "Art supplies", "cookie_offerings": 4, "sibling_conflicts": 2}
escli bulk --refresh wait_for --input children_of_the_world.ndjson
Santa 的 Elasticsearch 配置已经就绪,包含关键要素:
- Index : children-of-the-world
- Fields : name, age, nice_score, gift_preference, cookie_offerings, sibling_conflicts
现在,多亏了 escli , Santa 可以在地球上的任何地方查询它。甚至在飞行途中。
Santa 实际使用的真实命令
获取单个孩子的文档
escli get children-of-the-world "zoe-8yo-france"
搜索真正乖巧的孩子
echo '{
"query": {
"range": {
"nice_score": {"gte": 0.9}
}
}
}' | escli search \
--index children-of-the-world | jq
将淘气名单导出为 CSV 文件
echo '{
"query": "FROM children-of-the-world | WHERE nice_score < 0.2"
}' | escli esql query --format csv
为了防止手动导出 Naughty List 打断他们的 December stand-up 会议,精灵们最终将这个过程自动化了。
幸运的是,今年名单是空的,因为每个人都很乖。
自动补全: Santa 的新宠功能
escli 中最酷的功能之一就是 shell 自动补全。
安装自动补全:
eval "$(COMPLETE=bash ./escli)"
现在他可以输入:
eval "$(COMPLETE=bash ./escli)"
然后他的终端会智能地补全为:
escli esql query
连驯鹿都印象深刻。
圣诞节被 --help 拯救
Santa 在庞大的物流网络中,需要记住几乎无限的 API 选项,有时会忘记一两个 flag 。他并不感到羞愧。他高兴地使用 --help flag 来快速回忆。
escli --help
- 有文档的命令。
- 结构一致。
- 没有意外。
精灵们甚至抵制住了添加 ASCII 艺术的冲动(在一次小小的 “terminal meltdown incident” 之后)。
Santa 滚动查看帮助输出,微笑着低声说:“这太有用了!” 并按时送出了数十亿份礼物。
如果它对 Santa 足够好……
……那么也许对你的 Elasticsearch cluster 也足够好了。
今天就从 escli-rs 仓库下载最新的预发布版本并尝试吧。
我们很想听到你的反馈:在 GitHub 上打开一个 issue,让我们知道你的想法!
原文:https://discuss.elastic.co/t/dec-1st-2025-en-dear-santa-here-s-a-little-help-for-christmas/383561

1941

被折叠的 条评论
为什么被折叠?



