Spring Data Elasticsearch不会将null值写入插入的文档中。

huangapple go评论72阅读模式
英文:

Spring Data Elasticsearch is not writing null values to inserted documents

问题

我有一个ES实体

```java
@Document(indexName = "company")
public class CompanyEntity {

  @MultiField(
      mainField = @Field(type = Text, name = "alias_name"),
      otherFields = {@InnerField(suffix = "keyword", type = Keyword, nullValue = "NULL")})
  @Nullable
  private String aliasName;

 ...
}

如果我创建一个CompanyEntity对象并且不提供aliasName,我的期望是Spring Data Elasticsearch会为那些Nullable的实体属性持久化空值。但实际情况似乎并非如此,即使我在InnerField注解中提供了nullValue的值。

我确信我可能配置了某个注解错误,但我真的想使用Elasticsearch的null_value参数,详细信息在这里。但首先我需要理解如何让Spring Data Elasticsearch持久化空值。

感谢您花费时间!


<details>
<summary>英文:</summary>

I have an ES entity:

@Document(indexName = "company")
public class CompanyEntity {

@MultiField(
mainField = @Field(type = Text, name = "alias_name"),
otherFields = {@InnerField(suffix = "keyword", type = Keyword, nullValue = "NULL")})
@Nullable
private String aliasName;

...
}


If I create a CompanyEntity object and do not supply an aliasName, my expectation is that spring Data Elasticsearch would persist null values for entity properties that are ```Nullable```.  But this does not seem to be the case, even if I supply a value for the ```nullValue``` in the ```InnerField``` annotation.  

I&#39;m sure I have misconfigured an annotation or something, but I would really like to use Elasticsearch&#39;s ```null_value``` parameter as detailed [here][1].  But first I need to understand how to get SDE to persist null values.


Thank you for your time!


  [1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/null-value.html

</details>


# 答案1
**得分**: 2

由于空值无法被索引或搜索,因此通常 Spring Data Elasticsearch 不会存储它们,从而减小索引文档的大小。

然而,现在可以存储空值了,详细信息请参见 [这个问题](https://jira.spring.io/browse/DATAES-920),将会在版本 4.1.RC1 中包含,该版本预计明天发布。

**编辑:** 4.1.0.RC1 现已发布。

<details>
<summary>英文:</summary>

As null values can not be indexed or searched they are normally not stored by Spring Data Elasticsearch thus reducing the size of the indexed document.

The possibility to store null values nevertheless was added with [this issue](https://jira.spring.io/browse/DATAES-920) and will be contained in version 4.1.RC1  which should be released tomorrow.

**Edit:** 4.1.0.RC1 is released now

</details>



huangapple
  • 本文由 发表于 2020年9月15日 07:15:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/63892961.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定