Elasticsearch嵌套字段与深度?通过Kibana检查文档深度? [英] Elasticsearch Nested-field vs Depth? Check for document depth via Kibana?

查看:91
本文介绍了Elasticsearch嵌套字段与深度?通过Kibana检查文档深度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 elasticsearch ,我看到了以下两个术语:嵌套字段&深度。我认为这两个词相当。目前,我对这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:

  • "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起)深度不能超过20

By default (as of ES 6.3) the depth cannot exceed 20.

嵌套 数据类型允许索引对象数组并通过 嵌套查询。这意味着Elasticsearch将对具有此类字段的文档建立不同的索引(请参见

nested data type allows to index arrays of objects and query their items individually via nested query. What this means is that Elasticsearch will index a document with such fields differently (see the page Nested Objects of the Definitive Guide for more explanation).

例如,如果在下面的示例中我们未定义,则请参见《最终指南》中的嵌套对象。 用户 作为映射中嵌套字段,查询 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将为用户 列表作为隐式子文档,因此将使用更多的资源,更多的磁盘和内存。这就是为什么在映射上还有另一个设置的原因: index.mapping.nested_fields.limit 调节一个人可以声明多少个 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.

最有可能使用脚本执行此操作,请查看此博客文章以获取更多详细信息:在Kibana脚本化字段中使用无痛

Most likely you can do it with scripts, check this blog post for further details: Using Painless in Kibana scripted fields.

这篇关于Elasticsearch嵌套字段与深度?通过Kibana检查文档深度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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