Elasticsearch索引JSON带有逃脱的引号标记 - “总字段的限制[1000]已超过”
在升级了VOM Elasticsearch 5.6.10到7.15.1之后,JSON字符串带有逃逸的引号。当然,这导致了胡说八道。当我意识到这是我得到以下例外的那一刻:
primary java.lang.illegalgumentException拒绝了映射更新:总字段的限制[1000]已超过
索引代码类似于:
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)
debugging IDX_RECORD作为JSON
显示一个完全很好的JSON字符串,而没有引号,例如:
{
"uuid": "63fa7627-7d03-465b-93a3-a498feeb6689",
"contentType": null,
"description": null,
"descriptionURL": null,
...
}
Elasticsearch 7的配置中是否有一些我错过的东西?我们可以在Elasticsearch客户端上设置任何参数吗?还有其他想法吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了问题。可以猜测,这里使用的编程语言是Groovy(在圣杯上)。
idx_record作为JSON
需要在索引之前明确转换为字符串。因此,解决方案只是更改:singlerequest.source(idx_record as JSON,XCONTENTTYPE.JSON)
to
sing> singlerequest.source.source((idx_record as JSON).ToStRing(json).toString(),xcontenttype.json)
Found the problem. As one can guess, the programming language used here is Groovy (on Grails) .
idx_record as JSON
needed explicitly be converted to a String before being indexed. So the solution was simply changing:singleRequest.source(idx_record as JSON, XContentType.JSON)
to
singleRequest.source((idx_record as JSON).toString(), XContentType.JSON)