我们有一个spring引导应用程序,其中使用spring数据ElasticSearch。我们使用实体类来生成弹性索引。下面显示了一个这样的类-
import javax.persistence.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
/**
* The Class ElasticSearchSampleEntity.
*/
@Document(indexName = "Sample-index", type = "Sample-content")
public class ElasticSearchSampleEntity {
/**The es Sample entity id. */
@Id
@Field(type = FieldType.Long, index = true, name = "id")
private Long esSampleEntityId;
/**The es no of questions. */
@Field(type = FieldType.Integer, index = true)
private Integer esNoOfQuestions;
/**The es total marks. */
@Field(type = FieldType.Integer, index = true)
private Integer esTotalMarks;
/**The es total time min. */
@Field(type = FieldType.Short, index = true)
private Short esTotalTimeMin;
/**The es total time sec. */
@Field(type = FieldType.Short, index = true)
private Short esTotalTimeSec;
/**The es occurances. */
@Field(type = FieldType.Integer, index = true)
private Integer esOccurances;
/**The es rating. */
@Field(type = FieldType.Float, index = true)
private Float esRating;
/**The es created on. */
@Field(type = FieldType.Long, index = true)
private Long esCreatedDate;
/**The es updated on. */
@Field(type = FieldType.Long, index = true)
private Long esUpdatedDate;
/**The es published date. */
@Field(type = FieldType.Long, index = true)
private Long publishedDate;
/**The sample type id. */
@Field(type = FieldType.Integer, index = true)
private Integer sampleTypeId;
//getter and setter
}
这应该创建一次索引并将数据存储到弹性服务器。但是,在部署过程中,我们有时会遇到以下错误(间歇性问题)。
[main] ERROR o.s.boot.SpringApplication.reportFailure - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sampleController': Unsatisfied dependency expressed through field 'esSampleService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticSearchSampleServiceImpl': Unsatisfied dependency expressed through field 'esSampleRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticSearchSampleRepository': Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: mapper [sampleTypeId] cannot be changed from type [long] to [integer]
sampletypeid有时会被创建(或更新)很长时间,尽管我们特别提到它是integer。这就是问题的根源。我已经检查了数据类型,同时保存到弹性数据库以及这看起来不错。这是否意味着弹性索引会随着每次部署而更新。对于我们所做的数据库 spring.jpa.hibernate.ddl-auto=validate
同样地,对于弹性,我们能做同样的事情吗?我不明白为什么会发生这个问题。Map似乎很好。请帮帮我。
1条答案
按热度按时间brccelvz1#
下面是错误日志中的代码片段。
构造函数引发异常;嵌套异常为java.lang.illegalargumentexception:Map器[sampletypeid]不能从类型[long]更改为[integer]
看起来像是你之前创建的索引
sampleTypeId
定义为long
,现在您将此更改为int
这是不可能的,因此从elasticsearch抛出异常。您可以从elasticsearch get index mapping api中确认这一点,并检查
sampleTypeId
在索引中。