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

作者:来自 Elastic piotrprz

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

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

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

如果你在使用 Elastic Cloud Serverless,你可以依赖其中的很多东西,这些在一两年前并不一定具备,比如 semantic_text、EIS ( 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-...

相关推荐
Elasticsearch21 小时前
从 137,306 行日志定位到一个故障副本:在 Kibana 中排查错误激增
elasticsearch
Elasticsearch1 天前
State 即将弃用,由 cpu.mode 接替:在 Elastic 中迁移 OpenTelemetry 进程指标
elasticsearch
岳涛1 天前
考古|ES 5.3 三条改动只提前打招呼,布尔宽松写法到 6.0 才真正拒绝
elasticsearch
Elasticsearch1 天前
谁在发起请求?为 Amazon Bedrock AgentCore 智能体配置按用户划分的 Elasticsearch 访问权限
elasticsearch
Elasticsearch1 天前
Elasticsearch 日志写入提速:用 3 项设置和 logsdb_columnar 从每秒 5.2 万行提升到 11.2 万行
elasticsearch
Elastic 中国社区官方博客1 天前
Elastic 获得全新的 AWS 数据能力认证
大数据·人工智能·elasticsearch·搜索引擎·ai·云计算·aws
Elasticsearch2 天前
Elastic 获得全新的 AWS 数据能力认证
elasticsearch
Elasticsearch2 天前
Elastic 安全借助 NVIDIA Nemotron 为物理隔离的安全运营中心提供智能体人工智能
elasticsearch
Elasticsearch2 天前
NVIDIA Nemotron 现已在 Elastic 推理服务(EIS)中可用
elasticsearch