【问题标题】:How to save a String list or integer list from spring boot to elasticsearch如何将字符串列表或整数列表从spring boot保存到elasticsearch
【发布时间】:2020-07-30 03:18:36
【问题描述】:

我只想从我的 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”设置为null,则请求完成且没有任何错误

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

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的方式吗?

还有其他更好的方法吗?

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

【问题讨论】:

  • 你能发布你的映射吗?
  • 你能发布你的映射吗?假设您正在使用存储库,您正在保存的调用。你也可以发一下吗

标签: java spring-boot elasticsearch spring-data


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-18
    • 1970-01-01
    相关资源
    最近更新 更多