将集合作为值存储在Elasticearch中

hkmswyz6  于 2022-09-20  发布在  ElasticSearch
关注(0)|答案(1)|浏览(204)

我在弹性存储private Map<String, Set<String>>时遇到问题。

例如,我有一个变量private Map<String, Set<String>> updatedFields,其内容如下:

"updatedFields": {
    "key1": [
      "val1",
      "val2",
      "val3"
    ],
    "key2": [
      "val1",
      "val2",
      "val3"
    ]
  }

有了模板Map,"updatedFields": {"type": "object"}弹性将为存储的每个密钥创建自动Map。如果存储的唯一密钥超过1000个,则会导致以下错误:

failure in bulk execution:
[0]: index [md_activity_log_stg_ii], type [_doc], id [969d12df-d2c4-446f-975a-d95e76d6e720], message [ElasticsearchException[Elasticsearch exception [type=mapper_parsing_exception, reason=failed to parse]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=Limit of total fields [1000] has been exceeded while adding new fields [1]]];]

通过将设置更改为"updatedFields": {"type": "object", "enabled": false},将存储对象,但不存储数组的任何内容。

"updatedFields" : {
      "34b49fbb-7ca8-4dc2-8c1f-21f88324b393" : [ ]
 },

有谁知道您会配置字段,以便在不超过字段限制的情况下正确存储Map?

6ojccjat

6ojccjat1#

我假设您正在检索JSON并在Java中处理它。确保通过定义POJO定义或仅捕获所需的字段或嵌套字段。如果不这样做,ElasticSearch将动态Map任何插入的键,从而导致Map爆炸。

以下是ElasticSearch中可能帮助您解决问题的引用列表:

objectshttps://www.elastic.co/guide/en/elasticsearch/reference/current/object.html添加显式Map

添加限制以避免Map爆炸https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html#mapping-limit-settings

在常规https://www.elastic.co/guide/en/elasticsearch/reference/current/explicit-mapping.html中添加显式Map

相关问题