如何在ElasticSearch中正确定义哈希图 [英] How to properly define a hashmap in ElasticSearch

查看:142
本文介绍了如何在ElasticSearch中正确定义哈希图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ElasticSearch中使用动态映射.

I am using dynamic mapping in ElasticSearch.

我之所以使用它,是因为我的索引很长,因此我需要使用模板功能,以避免在多个位置更新定义(

I use it because my index is long and I need to use the template feature in order to avoid updating definitions in multiple places (see my other SO question).

我正在发送以下json(对象动物园),其包含一个HashMap 作为示例:

I am sending the following json (Object Zoo) which contains a HashMap as an example:

Put 127.0.0.1:9200/myIndex/Zoo/10
{
  "id" : 1,
  "Name" : "Madagascar",
  "map" : {
    "1" : {
      "id" : -4944060986111146989,
      "name" : null
    },
    "2" : {
      "id" : 5073063561743125202,
      "name" : null
    },
    "3" : {
      "id" : -1777985506870671559,
      "name" : null
    }
  }
}

这将创建以下索引

{
    "mm3_v2": {
        "mappings": {
            "Zoo": {
                "properties": {
                    "Name": {
                        "type": "string"
                    },
                    "id": {
                        "type": "long"
                    },
                    "map": {
                        "properties": {
                            "1": {
                                "properties": {
                                    "id": {
                                        "type": "long"
                                    }
                                }
                            },
                            "2": {
                                "properties": {
                                    "id": {
                                        "type": "long"
                                    }
                                }
                            },
                            "3": {
                                "properties": {
                                    "id": {
                                        "type": "long"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

在此示例中,哈希图中的内部对象很短.
在现实生活中,我的哈希图的对象可能很长.

In this example the inner object in the hashmap is short.
In real life my hashmap's object can be long.

这可以创建巨大的索引文件(轻松地1M行),并且对每个对象重复完全相同的定义.
(例如,当存储在列表中时,映射不会重复自身)

This can create a huge index files (easily 1M rows) and for each object it repeats exactly the same definition.
(e.g. when stored in a list, the mapping does not repeat itself)

有没有一种方法可以在弹性搜索中正确定义哈希图?

Is there a way to properly define a hashmap in elastic search?

推荐答案

有没有一种方法可以在弹性搜索中正确定义哈希图?

Is there a way to properly define a hashmap in elastic search?

在处理对象方面,Elasticsearch具有对象类型嵌套类型.嵌套对象被视为单独的文档,并且该文档提供了很好的示例来理解优点(和缺点).

In terms of handling objects, Elasticsearch has the Object Type and the Nested Type. Nested objects are treated as separate documents and the documentation provides good examples for understanding the advantages (and disadvantages).

我认为 Elasticsearch的动态模板对于您的情况可能值得探索,尽管您确实提到嵌套对象具有严格的定义,但是您想微调如何处理新的键值对添加项?

I think Elasticsearch's dynamic templates might be worth exploring for your case if you want to fine tune how new key value pair additions are treated although you did mention the nested objects have a rigid definition?

这可以创建一个巨大的索引文件(轻松地1M行),并且每个 对象,它重复完全相同的定义. (例如,当存储在 列表,则映射不会重复本身)

This can create a huge index files (easily 1M rows) and for each object it repeats exactly the same definition. (e.g. when stored in a list, the mapping does not repeat itself)

您是指要创建的大型映射吗?正如您提到的,使用Array类型可以避免这种情况,因此可以更改地图对象的结构来避免这种情况吗?还是地图键不像1、2、3,...那么简单?

Are you referring to the large mappings that will get created? As you mentioned, that can be avoided with the Array type and so would it be possible to change the structure of your map object to avoid this? Or are the map keys not as simple as 1, 2, 3,...?

这篇关于如何在ElasticSearch中正确定义哈希图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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