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

作者:来自 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...

相关推荐
INFINI Labs12 小时前
Easysearch analysis-ik 多词典性能优化:从性能回退到分词性能提升 25%~30%
elasticsearch·性能优化·分词·performance·easysearch·ik
IT飞牛13 小时前
Elasticsearch 技术调研与实践
大数据·elasticsearch·搜索引擎
从此以后自律13 小时前
Git一篇
大数据·elasticsearch·搜索引擎
超人也会哭️呀13 小时前
ES 混合检索(文本+向量)中的条件处理陷阱——当权限过滤遇到关键词查询
android·大数据·elasticsearch
做个文艺程序员1 天前
第03篇:深入 Mapping 与数据类型设计——ES Schema 设计避坑指南
大数据·elasticsearch·搜索引擎·mapping设计
铭毅天下1 天前
Easysearch 版本进化全图——从 ES 国产替代到 AI Native 搜索数据库
大数据·数据库·人工智能·elasticsearch·搜索引擎
Elastic 中国社区官方博客1 天前
在 Elasticsearch 中,存储向量查询速度最高提升 3 倍
大数据·人工智能·elasticsearch·搜索引擎·ai·全文检索
海兰1 天前
从原始日志到系统知识:补齐 AI 可观测性的“上下文层“
人工智能·elasticsearch
逆境不可逃1 天前
【与我学 ClaudeCode】规划与协调篇 之 Skills:按需加载的领域知识框架
大数据·人工智能·elasticsearch·搜索引擎·agent·claudecode
奋斗的老史1 天前
LangChain4j + Elasticsearch 实现企业级向量存储(支持混合检索、元数据过滤)
elasticsearch·langchain4j