Elasticsearch 索引 Json 带有转义引号 - "Limit of total fields [1000] has been exceeded"
Elasticsearch indexes Json with escaped quotation marks - "Limit of total fields [1000] has been exceeded"
将 vom Elasticsearch 5.6.10 升级到 7.15.1 后,Json 字符串使用转义引号编制索引。这当然会导致无意义的数据。我意识到的那一刻是当我收到以下异常时:
mapping update rejected by primary java.lang.IllegalArgumentException: Limit of total fields [1000] has been exceeded
索引代码如下:
for (...){
def idx_record = buildEsRecord(r) // getting a valid map without escape characters
if (idx_record != null) {
IndexRequest singleRequest = new IndexRequest(myIndex)
singleRequest.id(idx_record['_id'].toString())
idx_record.remove('_id')
singleRequest.source(idx_record as JSON, XContentType.JSON)
bulkRequest.add(singleRequest)
}
}
BulkResponse bulkResponse = esClient.bulk(bulkRequest, RequestOptions.DEFAULT)
调试 idx_record as JSON
显示完全正常的 Json 字符串,没有引号被转义,例如:
{
"uuid": "63fa7627-7d03-465b-93a3-a498feeb6689",
"contentType": null,
"description": null,
"descriptionURL": null,
...
}
Elasticsearch 7 的配置中是否有我遗漏的内容?我们可以在 Elasticsearch 客户端上设置任何参数吗?还有其他想法吗?
找到问题了。可以猜到,这里使用的编程语言是 Groovy (on Grails) 。 idx_record as JSON
需要在被索引之前显式转换为字符串。所以解决方案只是改变:
singleRequest.source(idx_record as JSON, XContentType.JSON)
到
singleRequest.source((idx_record as JSON).toString(), XContentType.JSON)
将 vom Elasticsearch 5.6.10 升级到 7.15.1 后,Json 字符串使用转义引号编制索引。这当然会导致无意义的数据。我意识到的那一刻是当我收到以下异常时:
mapping update rejected by primary java.lang.IllegalArgumentException: Limit of total fields [1000] has been exceeded
索引代码如下:
for (...){
def idx_record = buildEsRecord(r) // getting a valid map without escape characters
if (idx_record != null) {
IndexRequest singleRequest = new IndexRequest(myIndex)
singleRequest.id(idx_record['_id'].toString())
idx_record.remove('_id')
singleRequest.source(idx_record as JSON, XContentType.JSON)
bulkRequest.add(singleRequest)
}
}
BulkResponse bulkResponse = esClient.bulk(bulkRequest, RequestOptions.DEFAULT)
调试 idx_record as JSON
显示完全正常的 Json 字符串,没有引号被转义,例如:
{
"uuid": "63fa7627-7d03-465b-93a3-a498feeb6689",
"contentType": null,
"description": null,
"descriptionURL": null,
...
}
Elasticsearch 7 的配置中是否有我遗漏的内容?我们可以在 Elasticsearch 客户端上设置任何参数吗?还有其他想法吗?
找到问题了。可以猜到,这里使用的编程语言是 Groovy (on Grails) 。 idx_record as JSON
需要在被索引之前显式转换为字符串。所以解决方案只是改变:
singleRequest.source(idx_record as JSON, XContentType.JSON)
到
singleRequest.source((idx_record as JSON).toString(), XContentType.JSON)