问题描述
我收到此错误:
org.springframework.data.elasticsearch.ElasticsearchException:失败索引文档 [id: 1]
在org.springframework.data.elasticsearch.core.ElasticsearchTemplate.prepareIndex(ElasticsearchTemplate.java:1028)在org.springframework.data.elasticsearch.core.ElasticsearchTemplate.index(ElasticsearchTemplate.java:525)...
at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.prepareIndex(ElasticsearchTemplate.java:1028) at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.index(ElasticsearchTemplate.java:525) ...
每次我在实体 Book
类中放入一个 getIndexQuery
方法.所以它看起来像这样:
Every time that I put inside my entity Book
class a getIndexQuery
method. So it look like this:
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Document(indexName = "bookshop", type = "book", shards = 1, replicas = 0, refreshInterval = "-1")
public class Book {
@Id
private String bookId;
@Field(type = FieldType.String, store = true)
private String title;
public IndexQuery getIndexQuery(){
return new IndexQueryBuilder().withId(this.getBookId()).withObject(this).build();
}
}
即使我没有在代码中使用此方法,也会发生错误.如何将此方法放入我的实体类中,而不会弄乱实体模式(因为我认为这是错误的)?
The error occurs even when I do not use this method anyware in my code.How can I put this method inside my entity class without it messing with the enitties schema (becouse that is what I assume what is wrong)?
推荐答案
使用 @JsonIgnore.
@JsonIgnore
public IndexQuery getIndexQuery(){
return new IndexQueryBuilder().withId(this.getBookId()).withObject(this).build();
}
com.fasterxml.jackson.annotation.JsonIgnore
来自 jackson-core-2.8.1.jar
或添加此依赖项.
com.fasterxml.jackson.annotation.JsonIgnore
is from jackson-core-2.8.1.jar
or add this dependency.
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.1</version>
</dependency>
这篇关于实体类中的 IndexQueryBuilder 方法导致“无法索引文档 [id: 1]"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!