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

Elasticsearch exception : mappping depth in index has been exceeded

我在 Bonsai 上设置了一个 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