【问题标题】:object field starting or ending with a [.] makes object resolution ambiguous in elasticsearch bulk index以 [.] 开头或结尾的对象字段使弹性搜索批量索引中的对象分辨率不明确
【发布时间】:2020-07-22 04:08:37
【问题描述】:

我正在使用带有 java rest 高级客户端的 elasticsearch 版本 6.8.7。根据here 提供的文档,我编写了一个程序,该程序使用批量处理器将一些数据批量索引到elasticsearch。

问题是当我运行我的代码时,响应失败并显示以下消息:

[type=illegal_argument_exception, reason=object 以 [.] 开头或结尾的字段使对象解析不明确

这很奇怪,因为我手动索引了其中一个文档,它成功地没有任何问题。

这是发出索引请求的代码部分:

        String key = entry.getKey();
        JSONObject val = entry.getValue();
        bulkProcessor.add(new IndexRequest("tweet").type("json").id(key).source(val, XContentType.JSON));

这是一个 json 示例(上面的 val):

{"in_reply_to_status_id_str":null,"in_reply_to_status_id":null,"coordinates":null,"created_at":"星期一 4 月 6 日 23:59:47 +0000 2020","截断":false,"in_reply_to_user_id_str":null,"source":"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter 为了 iPhone","re​​tweet_count":0,"retweeted":false,"geo":null,"in_reply_to_screen_name":null,"is_quote_status":false,"id_str":"11111111111111","in_reply_to_user_id":null ,"favorite_count":7,"id":1111111111111,"text":"something","place":null,"contributors":null,"lang":"en","favorited":false}

如果有人知道为什么会发生这种情况,我会非常感谢他们的帮助。

更新: 我更改了索引,没有任何改变,但这是我在弹性终端中遇到的错误:

以 [.] 开头或结尾的对象字段使对象解析不明确: [{"possibly_sensitive_appealable":false,"in_reply_to_status_id_str":null,"in_reply_to_status_id":null,"created_at":"Mon Apr 06 23:59: 49 +0000 2020","in_reply_to_user_id_str":null,"source":"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android","quoted_status_id" :1111111111111,"retweet_count":0,"retweeted":false,"geo":null,"in_reply_to_screen_name":null,"is_quote_status":true,"id_str":"111111111111","in_reply_to_user_id":null,"favorite_count" :15,"id":1247313090397589511,"text":"something","place":null,"lang":"fa","favorited":false,"possibly_sensitive":false,"coordinates":null,"截断":false,"quoted_status_id_str":"1111111111111","contributors":null}]

【问题讨论】:

  • 您提供的示例 json 在字段名称 prnt.sc/rw8rq2 中没有任何点。有更好的例子吗?
  • @jzzfs 就是这样!字段名称中没有任何点的这个 json 会发生错误。
  • 您是否尝试过删除索引并重新开始?
  • @jzzfs 我使用了不同的索引,但我再次收到此错误。我用弹性终端页面上的错误更新了问题。
  • 我会将 bulkProcessor 包装在一个 for 循环中,并仅记录引发错误的有问题的 val。正如我所说,您在问题中包含的内容没有任何问题。

标签: java json elasticsearch


【解决方案1】:

我遇到了同样的问题,尝试验证属性,显然您的索引 GET /index_name 中的所有 properties 都存储为字符串而不是 JSON 对象。

如果这是你的情况:

问题最初是 Kafka ConsumerRecord raw,我没有设置类型 ConsumerRecord<String, String>,问题解决了。

其他选项是使用特定编码对字符串进行编码,它也适用于我。

例如

IndexRequest indexRequest = new IndexRequest("twitter")
  .source(record.value().getBytes(StandardCharsets.US_ASCII), XContentType.JSON);
IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT);
String id = indexResponse.getId();
log.info(id);

我不太确定这是否可以帮助您,但就我而言,我通过这些更改解决了问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-21
    • 2021-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-19
    • 1970-01-01
    相关资源
    最近更新 更多