问题描述
我在,我看到了以下两个术语:嵌套字段&深度。我认为这两个词相当。目前,我对这2个消息感到困惑。请问有人可以清除我吗?谢谢。
和顺便说一句,有什么方法可以通过Kibana检查文档深度吗?
I'm reading about mapping in elasticsearch and I see these 2 terms: Nested-field & Depth. I think these 2 terms are quite equivalent. I'm currently confused by these 2. Please can anyone clear me out? Thank you.And btw, are there any ways to check a document depth via Kibana?
对不起,我的英语。
推荐答案
混乱的根源可能是因为在Elasticsearch术语中,嵌套
可以在两个不同的上下文中使用:
The source of confusion is probably because in Elasticsearch term nested
can be used in two different contexts:
- 嵌套作为常规的,即JSON对象中的JSON对象;
- 嵌套作为Elasticsearch 。
- "nested" as a regular JSON notation nested, i.e. JSON object within JSON object;
- "nested" as Elasticsearch
nested
data type.
在,当他们提及深度他们指的是第一个含义。此处的设置 index.mapping.depth.limit
定义了JSON文档可以嵌套的深度。
In the mappings documentation page when they mention "depth" they refer to the first meaning. Here the setting index.mapping.depth.limit
defines how deeply nested can your JSON documents be.
以下是深度为1的JSON文档的示例:
Here is an example of JSON document with depth 1:
{
"name": "John",
"age": 30
}
现在深度为2:
{
"name": "John",
"age": 30,
"cars": {
"car1": "Ford",
"car2": "BMW",
"car3": "Fiat"
}
}
默认(自ES 6.3起)深度。
By default (as of ES 6.3) the depth cannot exceed 20.
数据类型允许索引对象数组并通过。这意味着Elasticsearch将对具有此类字段的文档建立不同的索引(请参见。 用户 作为映射中嵌套
字段,查询 user.first:约翰
和 user.last:白色
将返回一个匹配项,这将是一个错误:
For instance, if in the following example we do not define "user"
as nested
field in the mapping, a query for user.first: John
and user.last: White
will return a match and it will be a mistake:
{
"group" : "fans",
"user" : [
{
"first" : "John",
"last" : "Smith"
},
{
"first" : "Alice",
"last" : "White"
}
]
}
如果这样做,Elasticsearch将为用户
列表作为隐式子文档,因此将使用更多的资源,更多的磁盘和内存。这就是为什么在映射上还有另一个设置的原因:调节一个人可以声明多少个 nested
字段(默认为 50
)。要对此进行自定义,您可以查看。
If we do, Elasticsearch will index each item of the "user"
list as an implicit sub-document and thus will use more resources, more disk and memory. This is why there is also another setting on the mappings: index.mapping.nested_fields.limit
regulates how many different nested
fields one can declare (which defaults to 50
). To customize this you can see this answer.
因此,深度为>的Elasticsearch文档;除非您明确要求这样做,否则不会将1索引为嵌套
,这就是区别。
So, Elasticsearch documents with depth > 1 are not indexed as nested
unless you explicitly ask it to do so, and that's the difference.
是的,您可以!嵌套
中的$ c>嵌套个字段?只是为了消除这种混乱,是的,您可以在映射的 nested
字段内定义 nested
字段。看起来像这样:
Yes, you can! Just to stop this confusion, yes, you can define a nested
field inside nested
field in a mapping. It will look something like this:
PUT my_index
{
"mappings": {
"_doc": {
"properties": {
"user": {
"type": "nested",
"properties": {
"name": {
"type": "keyword"
},
"cars": {
"type": "nested",
"properties": {
"brand": {
"type": "keyword"
}
}
}
}
}
}
}
}
}
但是请记住,要建立索引的隐式文档的数量将成倍增加,并且效率不高。
But keep in mind that the amount of implicit documents to be indexed will be multiplied, and it will be simply not that efficient.
最有可能使用脚本执行此操作,请查看此博客文章以获取更多详细信息:。
Most likely you can do it with scripts, check this blog post for further details: Using Painless in Kibana scripted fields.
这篇关于Elasticsearch嵌套字段与深度?通过Kibana检查文档深度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!