【发布时间】:2020-04-22 11:40:46
【问题描述】:
我想使用 java 高级别的客户端插入一个对象。
我的映射如下:
"images":{
"type":"nested",
"properties":{
"name":{
"type":"text"
},
"url":{
"type":"text"
}
}
}
和java代码:
//productDb.getImages() 返回Image类型的ArrayList:带有属性“name”和“url”
productToIndex.put("images", new Gson().toJson(productDb.getImages()));
IndexRequest indexRequest = new IndexRequest(ProductIndex.PRODUCT_INDEX, ProductIndex.TYPE)
.source(productToIndex, XContentType.JSON);
try {
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
} catch (Exception e) {
logger.error("Data access error occured the entity persistence...", e);
throw new Exception(e);
}
错误是:
ElasticsearchStatusException[Elasticsearch 异常 [type=mapper_parsing_exception, reason=object mapping for [images] 试图将字段 [images] 解析为对象,但找到了具体值]]
具体值:
images -> [{"name":"Capture.PNG","url":"/api/trader/files/2132132/Capture.PNG"},{"name":"payement.jpg","url":"/api/trader/files/31231321/payement.jpg"}]
==> 对我来说似乎还可以,如果我将 productDb.getImages() 替换为 new Arraylist(); ,我不明白为什么它会返回异常;它工作正常(索引值为:“图像”:[])
我找不到如何使用 java 索引数组对象的示例,有解决方案吗?
谢谢。
【问题讨论】:
标签: java elasticsearch