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

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

相关推荐
Haooog8 小时前
Elasticsearch (ES) 面试题清单(不定时更新)
大数据·elasticsearch·搜索引擎·面试
武子康1 天前
大数据-184 Elasticsearch Doc Values 机制详解:列式存储如何支撑排序/聚合/脚本
大数据·后端·elasticsearch
周杰伦_Jay1 天前
【Elasticsearch】核心概念,倒排索引,数据操纵
大数据·elasticsearch·搜索引擎
cai_cai01 天前
springAlibaba + ollama + es 完成RAG知识库功能
大数据·elasticsearch·搜索引擎
库库茯苓1 天前
Kibana报错:Unable to retrieve version information from Elasticsearch nodes (解决方法)Window11环境
elasticsearch·kibana
nhdh1 天前
ELK(elasticsearch-7.6.2,kibana-7-6-2,Logstash-7.6.2)单节点部署
大数据·elk·elasticsearch
新元代码1 天前
Git在Windows环境下的安装与使用教程
大数据·elasticsearch·搜索引擎
小园子的小菜1 天前
深入理解Elasticsearch内部线程池:类型与核心作用解析
大数据·elasticsearch·搜索引擎
ZePingPingZe1 天前
SpringBoot整合Sharding-jdbc分库分表及ES搜索引擎解决无分片键查询
spring boot·elasticsearch·搜索引擎