Elasticsearch异常:超出了索引的映射深度

2019年9月10日 18点热度 0条评论

我在盆景上设置了Elasticsearch集群。我正在使用elasticsearch-rest-high-level-client库读取存储在Kafka中的Twitter推文,并将其推入Elasticsearch索引。

我得到以下异常:Exception in thread "main" ElasticsearchStatusException[Elasticsearch exception [type=illegal_argument_exception, reason=Limit of mapping depth [20] in index [twitter] has been exceeded due to object field [THIS CONTAINS ALL OF THE JSON MESSAGE RETRIEVED FROM KAFKA]
看来我的代码正在尝试将所有消息都放在一个字段中。可能出什么问题了?
IndexRequest indexRequest = new IndexRequest("twitter").source(jsonMessage, XContentType.JSON); IndexResponse indexResponse = restClient.index(indexRequest, RequestOptions.DEFAULT);

解决方案如下:

此错误与您尝试索引的Json的深度有关。默认映射深度为20表示您尝试索引的Json最多可以有20个深度的字段。例如

例如在json下面,shippingAddress的深度为3级

{
"order": {
    "orderNo": "test_order",
    "orderDate": "2020-01-01",
    "customer": {
        "customerName": "John Doe",
        "customerPhone": "555-555-5555",
        "shippingAddress": {
            "addressLine1": "test",
            "addressLine2": "test",
            "city": "test",
            "state": "test",
            "country": "test"
        }
    }
}

}

尽可能尝试优化您的文档。如果不是,则可以根据实际需要更新设置,

index.mapping.depth.limit - The maximum depth for a field, which is measured as the number of inner objects. For instance, if all fields are defined at the root object level, then the depth is 1. If there is one object mapping, then the depth is 2, etc. The default is 20.

检查文件

https://www.elastic.co/guide/en/elasticsearch/reference/7.6/mapping.html#mapping-limit-settings