Elasticsearch:在 X-mas 吃一些更健康的东西

作者:来自 Elastic piotrprz

我希望在假期里,你们也在吃健康的东西,而不只是甜蛋糕

假设你想提前买一些水果,你可能不知道所有的名字,也可能不知道你实际上想吃哪种水果,商店的库存里有很多东西,或者(就像我一样)你在国外过假期。

这里可以帮上忙的是一个不错的、低成本、多语言的语义搜索。

如果你在使用 Elastic Cloud Serverless,你可以依赖其中的很多东西,这些在一两年前并不一定具备,比如 semantic_textEIS ( Elastic Inference Service ),或者来自 Jina 的多语言密集向量模型,它在 EIS 中默认启用,不需要让你的 GPU 吃力,也不需要你提前规划 ML 节点。

更多阅读:Elasticsearch:使用推理端点及语义搜索演示

假设商店用来保存库存的索引真的非常、非常简单(为了简单起见,我们跳过名称、SKU 和其他内容)。

markdown 复制代码
`

1.  PUT inventory
2.  {
3.    "mappings": {
4.      "properties": {
5.        "item": {
6.          "type": "semantic_text",
7.          "inference_id": ".jina-embeddings-v3"
8.        }
9.      }
10.    }
11.  }

`AI写代码![](https://csdnimg.cn/release/blogv2/dist/pc/img/runCode/icon-arrowwhite.png)

然后,让我们用一些可以购买的商品来填充它:

bash 复制代码
`

1.  POST inventory/_bulk?refresh=true
2.  { "index": { } }
3.  { "item": "cherries 🍒" }
4.  { "index": { } }
5.  { "item": "train 🚆" }
6.  { "index": { } }
7.  { "item": "bananas 🍌" }
8.  { "index": { } }
9.  { "item": "computer 💻" }
10.  { "index": { } }
11.  { "item": "apple 🍎" }
12.  { "index": { } }
13.  { "item": "framboises 🍓" }
14.  { "index": { } }
15.  { "item": "der Apfel 🍏" }
16.  { "index": { } }
17.  { "item": "tomato 🍅" }
18.  { "index": { } }
19.  { "item": "das Auto 🚗" }
20.  { "index": { } }
21.  { "item": "bicycle 🚲" }
22.  { "index": { } }
23.  { "item": "naranjas 🍊" }

`AI写代码![](https://csdnimg.cn/release/blogv2/dist/pc/img/runCode/icon-arrowwhite.png)

请注意,在库存中我们保存了来自所有部门的商品,而且它们使用 English、 French、 German 和 Spanish。

在我们运行 POST inventory/_search 之后,应该可以以随机顺序看到所有商品。

但是,当我想吃一些水果时,在 Polish 中是 "owoce"(顺便说一下这是复数 BTW),那么我所需要的只是:

json 复制代码
`

1.  POST inventory/_search
2.  {
3.    "query": {
4.      "match": {
5.        "item": "owoce" // this stands for "fruit" in Polish
6.      }
7.    }
8.  }

`AI写代码

我们得到的返回结果如下:

bash 复制代码
`

1.  {
2.    "took": 251,
3.    "timed_out": false,
4.    "_shards": {
5.      "total": 3,
6.      "successful": 3,
7.      "skipped": 0,
8.      "failed": 0
9.    },
10.    "hits": {
11.      "total": {
12.        "value": 11,
13.        "relation": "eq"
14.      },
15.      "max_score": 0.6704586,
16.      "hits": [
17.        {
18.          "_index": "inventory",
19.          "_id": "8EtNK5sBRerpcHC7zVrq",
20.          "_score": 0.6704586,
21.          "_source": {
22.            "item": "cherries 🍒"
23.          }
24.        },
25.        {
26.          "_index": "inventory",
27.          "_id": "9EtNK5sBRerpcHC7zVrr",
28.          "_score": 0.6327668,
29.          "_source": {
30.            "item": "apple 🍎"
31.          }
32.        },
33.        {
34.          "_index": "inventory",
35.          "_id": "-ktNK5sBRerpcHC7zVrr",
36.          "_score": 0.61157316,
37.          "_source": {
38.            "item": "naranjas 🍊"
39.          }
40.        },
41.        {
42.          "_index": "inventory",
43.          "_id": "8ktNK5sBRerpcHC7zVrr",
44.          "_score": 0.6047706,
45.          "_source": {
46.            "item": "bananas 🍌"
47.          }
48.        },
49.        {
50.          "_index": "inventory",
51.          "_id": "9UtNK5sBRerpcHC7zVrr",
52.          "_score": 0.60331476,
53.          "_source": {
54.            "item": "framboises 🍓"
55.          }
56.        },
57.        {
58.          "_index": "inventory",
59.          "_id": "9ktNK5sBRerpcHC7zVrr",
60.          "_score": 0.5917518,
61.          "_source": {
62.            "item": "der Apfel 🍏"
63.          }
64.        },
65.        {
66.          "_index": "inventory",
67.          "_id": "90tNK5sBRerpcHC7zVrr",
68.          "_score": 0.5634274,
69.          "_source": {
70.            "item": "tomato 🍅"
71.          }
72.        },
73.        {
74.          "_index": "inventory",
75.          "_id": "-UtNK5sBRerpcHC7zVrr",
76.          "_score": 0.50522983,
77.          "_source": {
78.            "item": "bicycle 🚲"
79.          }
80.        },
81.        {
82.          "_index": "inventory",
83.          "_id": "80tNK5sBRerpcHC7zVrr",
84.          "_score": 0.5001138,
85.          "_source": {
86.            "item": "computer 💻"
87.          }
88.        },
89.        {
90.          "_index": "inventory",
91.          "_id": "-EtNK5sBRerpcHC7zVrr",
92.          "_score": 0.48864484,
93.          "_source": {
94.            "item": "das Auto 🚗"
95.          }
96.        }
97.      ]
98.    }
99.  }

`AI写代码![](https://csdnimg.cn/release/blogv2/dist/pc/img/runCode/icon-arrowwhite.png)收起代码块![](https://csdnimg.cn/release/blogv2/dist/pc/img/arrowup-line-top-White.png)

这告诉我们几件事情:

  • 与几年前和早期版本相比,现在创建和运行语义搜索要简单得多;将 semantic_text 和运行在 EIS 中的 models 结合起来让事情变得非常容易:不需要安装模型,不需要担心容量规划,也不需要多次网络往返来获取 embeddings(无论是存储还是搜索),等等。
  • 如果你有一个 multi-language 模型,那会非常有帮助,并且可以节省翻译工作。
  • 我们知道 tomato 是一种水果,但也许我们不应该把它加到水果沙拉里 :slight_smile

今天就到这里。我祝你有一个健康的饮食和健康的集群 :slight_smile:

原文:discuss.elastic.co/t/dec-25th-...

相关推荐
阿里云大数据AI技术1 小时前
Agentic Search 2.0:从单轮对话迈向企业级 AI 搜索自动驾驶Agent
人工智能·elasticsearch·agent
Elasticsearch4 小时前
你的 AI agent 需要一个不在场证明:Elastic 中 Agent Builder 的可观测性和审计追踪
elasticsearch
Elasticsearch7 小时前
仪表板活动日志:了解哪些 Kibana 仪表板会被使用
elasticsearch
Elasticsearch1 天前
从 22.61GB 到 15.63GB:Elasticsearch 9.5 如何用「混合存储」重新定义日志数据库
elasticsearch
Elasticsearch1 天前
用于自托管 LLM 调优的 vLLM Prometheus 指标:TTFT、KV Cache 和 GPU 利用率
elasticsearch
Sayai1 天前
Elasticsearch 快照备份到 NAS(NFS)实战:SLM 自动化 + 365 天保留策略
elasticsearch·自动化·jenkins
JavaPub-rodert2 天前
写软著 - Copyright Forge Skill 完整闭环改造方案
大数据·elasticsearch·搜索引擎
Elastic 中国社区官方博客2 天前
从建议到修复的 4 个阶段:使用 Elastic Workflows 实现人在回路中的自动化
运维·数据库·人工智能·后端·elasticsearch·ai·自动化
Elasticsearch2 天前
使用 OpenTelemetry 进行 Android 应用监控:从点击到后端的分布式追踪
elasticsearch
Elasticsearch2 天前
安心睡过凌晨 3 点的告警:在 Red Hat OpenShift 上使用 Elastic 实现自动化故障事件响应
elasticsearch