英文:
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'm sure I have misconfigured an annotation or something, but I would really like to use Elasticsearch'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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论