为什么我们在设置存储库时要在elasticsearch中创建映射?

发布于 2025-01-11 12:34:08 字数 287 浏览 0 评论 0原文

好的,我明白了这个问题,即需要什么映射。

现在我正在查看一段代码,他们正在做的是在创建弹性搜索存储库时通过推送虚拟对象然后删除它来生成映射。

我知道弹性搜索可以生成映射,但是这样做有什么意义呢?它对搜索查询没有帮助(至少是我尝试过的正则表达式,除非您在映射中明确告知这是关键字类型)。

如果有人能解释这一点,我将不胜感激。

Okay, I got it this question that what is the need for mapping.

Now I am going through a piece of code, what they are doing is that they are generating the mapping while creating the elastic search repository by pushing a dummy object and then deleting it.

I got it that elastic search can generate mappings, but what is the point of doing so. It does not help with the search queries ( at least the regex one that I have tried unless you explicitly tell in your mapping that this is of type keyword).

I would be thankful if someone can explain this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤君无依 2025-01-18 12:34:08

虽然 Elasticsearch 会在您未定义映射时生成映射,并且仅对文档进行索引,但这样 Elasticsearch 会根据第一个文档数据生成映射,例如您的文档中有 product-id 字段索引,如果您在没有定义显式映射的情况下对其进行索引,则当您索引 product 时,Elasticsearch 会为此字段生成两种数据类型,一种是 text,另一种是 keyword -id 如下。

{
"product-id" : "1"
}

现在,这取决于您的用例,假设在您的情况下,product-id 是关键字并且是固定的,您只想使用精确搜索聚合product-id字段上,并且不想要全文搜索,那么你最好使用显式映射并将其定义为keyword 字段,这样 Elasticsearch 存储和查询将是最佳的。您可以参考此Stackoverflow评论,了解更多信息。

底线,当您想要更好地控制数据的索引方式时,定义显式映射总是比依赖 Elasticsearch 生成的默认映射更好。

Although Elasticsearch generates the mapping when you don't define one, and just index the document, but that way Elasticsearch generates the mapping based on the first document data, for example you have product-id field in your index, and if you index it without defining explicit mapping, Elasticsearch generates two data-type, one is text and another is keyword for this field when you index product-id as below.

{
"product-id" : "1"
}

Now, it depends on your use-case, let's suppose in your case, product-id is keyword and fixed, and you just want to use the exact search or aggregation on the product-id field, and don't want the full-text search, than you better go with explicit mapping and define it as in keyword field, that way Elasticsearch storage and queries would be optimal. You can refer to this Stackoverflow comment, for more information on it.

Bottomline, When you want to have a greater control on how your data should be indexed, It's always better to define explicit mapping than relaying on default mapping generated by Elasticsearch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文