在弹簧数据弹性搜索中进行挑选时,如何忽略零字段

发布于 2025-02-09 03:01:21 字数 1040 浏览 0 评论 0原文

我保存了两个对象。

@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?

null_fields

I have tried setting this spring.jackson.default-property-inclusion=non_null in property files. It doesn't work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏雨凉 2025-02-16 03:01:21

弹簧数据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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文