【发布时间】: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","retweet_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