为什么我需要“存储":“是"?在弹性搜索? [英] Why do I need "store":"yes" in elasticsearch?

查看:24
本文介绍了为什么我需要“存储":“是"?在弹性搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的不明白为什么在核心类型链接中它在属性中说描述(例如数字):

I really don't understand why in core types link it says in the attributes descriptions (for a number, for example):

  1. store - 设置为 yes 以在索引中存储实际字段,no 不存储它.默认为 no(注意,JSON 文档本身已存储,可以从中检索)
  2. index - 如果该值不应被索引,则设置为 no.在这种情况下,store 应该设置为 yes,因为如果它没有被索引并且没有被存储,与它无关

粗体的两个部分似乎相互矛盾.如果 "index":"no", "store":"no" 我仍然可以从源中获取值.例如,如果我有一个包含 URL 的字段,这可能是一个很好的用途.没有?

The two bold parts seem to contradict. If "index":"no", "store":"no" I could still get the value from the source. This could be a good use if I have a field containing a URL for example. No?

我做了一个小实验,我有两个映射,一个字段设置为 "store":"yes",另一个字段设置为 "store":"no".

I had a little experiment, where I had two mappings, in one a field was set to "store":"yes" and in the other to "store":"no".

在这两种情况下,我仍然可以在查询中指定:

In both cases I could still specify in my query:

{"query":{"match_all":{}}, "fields":["my_test_field"]}

我得到了相同的答案,返回了字段.

and I got the same answer, returning the field.

我认为如果 "store" 设置为 "no" 就意味着我无法检索特定字段,但必须获取整个 _source 并在客户端解析.

I thought that if "store" is set to "no" it would mean I could not retreive the specific field, but had to get the whole _source and parse it on the client side.

那么,将 "store" 设置为 "yes" 有什么好处?仅当我从 "_source" 字段中明确排除该字段时才相关吗?

So, what benefit is there in setting "store" to "yes"? Is it only relevant if I exclude the field from the "_source" field explicitly?

推荐答案

我认为如果商店"设置为否",那将意味着我不能检索特定字段,但必须获取整个 _source 和在客户端解析它.

I thought that if "store" is set to "no" it would mean I could not retrieve the specific field, but had to get the whole _source and parse it on the client side.

这正是当字段未存储(默认)并且 _source 字段已启用(也是默认)时 elasticsearch 为您所做的.

That's exactly what elasticsearch does for you when a field is not stored (default) and the _source field is enabled (default too).

您通常将一个字段发送到 elasticsearch,因为您要么想搜索它,要么检索它.但确实,如果您不显式存储该字段并且不禁用源,您仍然可以使用 _source 检索该字段.这意味着在某些情况下,拥有一个既没有索引也没有存储的字段实际上可能是有意义的.

You usually send a field to elasticsearch because you either want to search on it, or retrieve it. But it's true that if you don't store the field explicitly and you don't disable the source you can still retrieve the field using the _source. This means that in some cases it might actually make sense to have a field that is not indexed nor stored.

当您存储一个字段时,这是在底层 lucene 中完成的.Lucene 是一个倒排索引,它允许快速全文搜索并在给定文本查询的情况下返回文档 ID.除了倒排索引之外,Lucene 还具有某种存储方式,可以存储字段值以便在给定文档 ID 的情况下进行检索.您通常将要作为搜索结果返回的字段存储在 lucene 中.Elasticsearch 不需要存储您想要返回的每个字段,因为它总是默认存储您发送给它的每个文档,因此它始终能够将您发送给它的所有内容作为搜索结果返回.

When you store a field, that's done in the underlying lucene. Lucene is an inverted index, that allows for fast full-text search and gives back document ids given text queries. Beyond the inverted index Lucene has some kind of storage where the field values can be stored in order to be retrieved given a document id. You usually store in lucene the fields that you want to return as search results. Elasticsearch doesn't require to store every field that you want to return because it always stores by default every document that you send to it, thus it's always able to return everything you sent to it as search result.

在少数情况下,在 lucene 中显式存储字段可能很有用:当 _source 字段被禁用时,或者当我们想要避免解析它时,即使解析是由自动完成的弹性搜索.请记住,虽然从 lucene 检索许多存储的字段可能需要每个字段进行一次磁盘搜索,而仅从 lucene 检索 _source 并解析它以检索所需的字段只是一次磁盘搜索和大多数情况下只是更快.

In just a few cases it might be useful to store fields explicitly in lucene: when the _source field is disabled, or when we want to avoid parsing it, even if the parsing is done automatically by elasticsearch. Keep in mind though that retrieving many stored fields from lucene might require one disk seek per field while with retrieving only the _source from lucene and parsing it in order to retrieve the needed fields is just a single disk seek and just faster in most of the cases.

这篇关于为什么我需要“存储":“是"?在弹性搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆