首页 > 解决方案 > 如何将字符串列表或整数列表从spring boot保存到elasticsearch

问题描述

我只想从我的 Spring Boot 应用程序传递一个整数列表/字符串列表以保存在我的弹性搜索数据存储中。我正在通过邮递员发送请求,但它给出了以下错误。

"status": 500,
"error": "Internal Server Error",
"message": "Elasticsearch exception [type=mapper_parsing_exception, reason=object mapping for [abPath] tried to parse field [null] as object, but found a concrete value]"

我的模型类abPath类变量配置如下

@Field( type = FieldType.Integer, store = true)
private List<Integer> abPath;

我的 Postman 请求属性设置如下

"abPath": [1, 2, 3]

如果我将“abPath”设置为空,则请求完成且没有任何错误

之后我找到了一种保存方法如下

public class AB{
   private Integer abId;
   // constructor and getter setter
}

//then i update my model
@Field( type = FieldType.Nested)
private List<AB> abPath;

//then postman request updated as follows
"abPath" : [{"abId" : 1}, {"abId" : 2}]

然后请求完成,没有任何错误..

我想知道的是,

这是将整数列表或字符串列表保存到elasticsearch中的方法吗?

还有其他更好的方法吗?

我可以保存整数列表或字符串列表而不像我一样将值包装到任何其他对象中吗?

标签: javaspring-bootelasticsearchspring-data

解决方案


在我看来,您实施的方式是一个好方法。使用这种方法,我们甚至可以查询内部字段。我也以同样的方式管理它。


推荐阅读