Elasticsearch索引JSON带有逃脱的引号标记 - “总字段的限制[1000]已超过”

发布于 2025-01-22 11:29:36 字数 999 浏览 0 评论 0 原文

在升级了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客户端上设置任何参数吗?还有其他想法吗?

After having upgraded vom Elasticsearch 5.6.10 to 7.15.1, Json strings are indexed with escaped quotation marks. This leads to nonsense data of course. The moment I realised it was when I got the following exception:

mapping update rejected by primary java.lang.IllegalArgumentException: Limit of total fields [1000] has been exceeded

The indexing code is like:

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 as JSON shows a totally fine Json string without quotation marks being escaped, like:

{
    "uuid": "63fa7627-7d03-465b-93a3-a498feeb6689",
    "contentType": null,
    "description": null,
    "descriptionURL": null,
    ...
}

Is there something in the configuration of Elasticsearch 7 that I have missed? Can we set any parameters on the Elasticsearch client? Any other ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸵鸟症 2025-01-29 11:29:36

找到了问题。可以猜测,这里使用的编程语言是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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文