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-...

相关推荐
老纪的技术唠嗑局4 小时前
告别OpenClaw配置丢失——Mindkeeper内测版邀测
大数据·elasticsearch·搜索引擎
Elasticsearch5 小时前
使用 Elasticsearch + Jina embeddings 进行无监督文档聚类
elasticsearch
勇哥的编程江湖7 小时前
flinkcdc streaming 同步数据到es记录过程
大数据·elasticsearch·flink·flinkcdc
曾阿伦7 小时前
Elasticsearch 7.x 常用命令备忘录
大数据·elasticsearch·搜索引擎
斯特凡今天也很帅8 小时前
Elasticsearch数据库专栏(二)DSL语句总结(更新中)
大数据·elasticsearch·搜索引擎
要记得喝水8 小时前
适用于 Git Bash 的脚本,批量提交和推送多个仓库的修改
git·elasticsearch·bash
二十七剑8 小时前
Elasticsearch的索引问题
大数据·elasticsearch·搜索引擎
A__tao17 小时前
Elasticsearch Mapping 一键生成 Java 实体类(支持嵌套 + 自动过滤注释)
java·python·elasticsearch
A__tao19 小时前
Elasticsearch Mapping 一键生成 Proto 文件(支持嵌套 + 注释过滤)
大数据·elasticsearch·jenkins
Devin~Y19 小时前
高并发电商与AI智能客服场景下的Java面试实战:从Spring Boot到RAG与向量数据库落地
java·spring boot·redis·elasticsearch·spring cloud·kafka·rag