【问题标题】:Is there a way to trigger spring-elastic-search mapping type when a field value is null by default?当字段值默认为 null 时,有没有办法触发 spring-elastic-search 映射类型?
【发布时间】:2021-02-03 22:31:10
【问题描述】:

在我们当前的 Spring-data-elasticsearch v.4.0.4 应用程序中,我们在 POJO 上使用 @Document,我们注意到,只要我们有一个空值字段,该字段在 Elasticsearch 中就没有映射类型。因此,当我们对该字段运行查询和排序时,我们会遇到 Elasticsearch 错误No mapping found for [view_date] in order to sort on

我们尝试在 v.4.1.0 中使用 @FieldstoreNulValue 选项,该字段显示在索引中。但是,在 Elasticsearch 中仍然没有该字段的映射类型,当我们对该空值字段进行排序时,我们仍然会看到 no mapping found 错误。

即使字段为空值,有没有办法触发映射?

【问题讨论】:

    标签: spring-data-elasticsearch


    【解决方案1】:

    如何为索引创建映射?当使用 Spring Data Elasticsearch 创建映射时,这是在没有特殊实体的情况下完成的,并且不知道特殊实例是否具有空值属性。然后使用 storeNullValue 参数。

    当您使用 Spring Data Elasticsearch 存储库并且索引尚不存在时,将自动创建映射。或者您需要自己拨打IndexOperations.create()IndexOperations.putMapping()

    【讨论】:

    • 我们使用 esOperations.bulkIndex() 来索引我们的数据。我们的 POJO 上有 @Document,并依靠 SDES 根据文档 docs.spring.io/spring-data/elasticsearch/docs/current-SNAPSHOT/… 自动创建具有相应映射的索引
    • 那么映射是否有一个名为 view_date 的字段?检查 _/indexname/mappings 端点从 Elasticsearch 返回的内容
    • _/indexname/mappings 不返回 view_date 的映射类型。但是,我能够在 view_date 字段上使用indexOperations.putMapping(indexOperations.createMapping(resourceClass))@Field (type=Long) 将映射添加到ES。
    • 那么索引最初不是由 Spring Data Elasticsearch 创建的。因此,当现在添加映射时,您的排序应该可以工作。
    • 是的。看起来在实体上有 @Document 并不能保证在索引期间会创建映射。基于上面链接中的 Spring ES 文档,我们所依赖的东西。
    猜你喜欢
    • 1970-01-01
    • 2019-08-17
    • 1970-01-01
    • 1970-01-01
    • 2012-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-03
    相关资源
    最近更新 更多