英文:
object field starting or ending with a [.] makes object resolution ambiguous in elasticsearch bulk index
问题
我正在使用Elasticsearch版本6.8.7和Java Rest High Level客户端。我编写了一个程序,使用批量处理器(bulk processor)将一些数据批量索引到Elasticsearch,根据提供的文档这里。
问题是当我运行我的代码时,响应失败并显示以下消息:
[type=illegal_argument_exception, reason=object field starting or ending with a [.] makes object resolution ambiguous
这相当奇怪,因为我手动索引了其中的一个文档,而且没有任何问题。
这是代码中发起索引请求的部分:
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": "Mon Apr 06 23:59:47 +0000 2020",
"truncated": false,
"in_reply_to_user_id_str": null,
"source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>",
"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
}
如果有人对为什么会发生这种情况有任何想法,我会非常感谢他们的帮助。
更新:
我更改了索引但没有任何变化,但这是我在Elasticsearch终端中收到的错误消息:
object field starting or ending with a [.] makes object resolution ambiguous: [...]
英文:
I am using elasticsearch version 6.8.7 with java rest high level client. I coded a program that uses bulk processor to bulk index some data to elasticsearch, according to the documentation provided here.
The problem is when I run my code, response fails with the message:
> [type=illegal_argument_exception, reason=object field starting or ending with a [.] makes object resolution ambiguous
which is quite strange because I indexed one of the documents manually and it succeeded without any problem.
this is the part of the code that makes a index request:
String key = entry.getKey();
JSONObject val = entry.getValue();
bulkProcessor.add(new IndexRequest("tweet").type("json").id(key).source(val, XContentType.JSON));
and this is a sample of the json (val in the above):
> {"in_reply_to_status_id_str":null,"in_reply_to_status_id":null,"coordinates":null,"created_at":"Mon
> Apr 06 23:59:47 +0000
> 2020","truncated":false,"in_reply_to_user_id_str":null,"source":"<a
> href="http://twitter.com/download/iphone" rel="nofollow">Twitter
> for
> iPhone</a>","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}
If anyone has any ideas why this happens, I would very much appriciate their help.
update:
I changed the index nothing changed but this is the error I get in elastic terminal:
> object field starting or ending with a [.] makes object resolution ambiguous: [{"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":"<a href="http://twitter.com/download/android" rel="nofollow">Twitter for Android</a>","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,"truncated":false,"quoted_status_id_str":"1111111111111","contributors":null}]
答案1
得分: 0
我遇到了同样的问题,尝试验证属性,显然你的索引 GET /index_name
中的所有 properties
都以字符串形式存储,而不是 JSON 对象。
如果你的情况是这样的:
最初问题出在 Kafka 的 ConsumerRecord
上,我没有设置类型 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);
我不太确定这是否对你有帮助,但在我的情况下,通过这些更改解决了问题。
英文:
I had the same problem, try to validate the properties, apparently all the properties
in your index GET /index_name
are store as String and not as a JSON object.
If this is your case:
The problem initially was with Kafka ConsumerRecord
raw, I didn't set the types ConsumerRecord<String, String>
and the problem was resolved.
Other option is to encode the string with a specific Encoding and also it works for me.
e.g.
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);
I'm not pretty sure that this could help you, but in my case I resolve the problem with those changes.
专注分享java语言的经验与见解,让所有开发者获益!
评论