为什么我们在设置存储库时要在elasticsearch中创建映射?
好的,我明白了这个问题,即需要什么映射。
现在我正在查看一段代码,他们正在做的是在创建弹性搜索存储库时通过推送虚拟对象然后删除它来生成映射。
我知道弹性搜索可以生成映射,但是这样做有什么意义呢?它对搜索查询没有帮助(至少是我尝试过的正则表达式,除非您在映射中明确告知这是关键字类型)。
如果有人能解释这一点,我将不胜感激。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然 Elasticsearch 会在您未定义映射时生成映射,并且仅对文档进行索引,但这样 Elasticsearch 会根据第一个文档数据生成映射,例如您的文档中有
product-id
字段索引,如果您在没有定义显式映射的情况下对其进行索引,则当您索引product 时,Elasticsearch 会为此字段生成两种数据类型,一种是
如下。text
,另一种是keyword
-id现在,这取决于您的用例,假设在您的情况下,
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 istext
and another iskeyword
for this field when you indexproduct-id
as below.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 theexact search
oraggregation
on theproduct-id
field, and don't want thefull-text search
, than you better go with explicit mapping and define it as inkeyword
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.