在弹簧数据弹性搜索中进行挑选时,如何忽略零字段
我保存了两个对象。
@Document(indexName = "test_index", createIndex = false)
public class ZTest {
@Id
private String id;
private String testOne;
@Transient
private String testTwo;
private String testThree;
}
{
"_index" : "test_index",
"_type" : "_doc",
"_id" : "w0mCgYEBXSVfca67-ayl",
"_score" : 1.0,
"_source" : {
"_class" : "com.ZTest",
"testOne" : "test_one"
}
},
{
"_index" : "test_index",
"_type" : "_doc",
"_id" : "xEmLgYEBXSVfca67r6wf",
"_score" : 1.0,
"_source" : {
"_class" : "com.ZTest",
"testOne" : "test_one",
"testThree" : "test_three"
}
}
Iterable<ZTest> t = zTestRepository.findAll();
是否可以在读取结果中排除这些空字段?
我已经尝试在今年春季设置。它行不通。
I have saved two objects.
@Document(indexName = "test_index", createIndex = false)
public class ZTest {
@Id
private String id;
private String testOne;
@Transient
private String testTwo;
private String testThree;
}
{
"_index" : "test_index",
"_type" : "_doc",
"_id" : "w0mCgYEBXSVfca67-ayl",
"_score" : 1.0,
"_source" : {
"_class" : "com.ZTest",
"testOne" : "test_one"
}
},
{
"_index" : "test_index",
"_type" : "_doc",
"_id" : "xEmLgYEBXSVfca67r6wf",
"_score" : 1.0,
"_source" : {
"_class" : "com.ZTest",
"testOne" : "test_one",
"testThree" : "test_three"
}
}
Iterable<ZTest> t = zTestRepository.findAll();
Is it possible to exclude those null fields in the read result?
I have tried setting this spring.jackson.default-property-inclusion=non_null in property files. It doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
弹簧数据Elasticsearch返回实体,这些Java Pojo实体具有3个定义的属性。对于瞬态或未返回的属性属性,当创建实体类的对象上时,属性值将是在对象中设置的值 - 此处为null。
您期望还会返回什么?
Spring Data Elasticsearch returns entities, and these Java POJO entities have 3 defined properties. And for properties that are transient or that are not returned by Elasticsearch the property value will be the value that is set in the object when on object of the entity class is created - here it's null.
What else do you expect to be returned?