Elasticsearch 在启动期间抛出错误
Elasticsearch throwing an error during startup
我已经在 spring 引导中实现了 Elasticsearch。每次重新启动服务器时,我都会收到以下错误。
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productController': Unsatisfied dependency expressed through field 'ps'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productServiceImpl': Unsatisfied dependency expressed through field 'pr'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productRepository': 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: Rejecting mapping update to [products] as the final mapping would have more than 1 type: [_doc, product]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
我每次启动服务器然后执行索引时都删除了索引。任何人都可以向我建议解决方案
Elasticsearch v6 及更高版本的每个索引不能有超过一种类型。但是从你的例外情况来看,你的映射试图在索引上创建多个类型(_doc 和产品)
参考https://www.elastic.co/guide/en/elasticsearch/reference/6.0/removal-of-types.html了解更多信息。
正如来自 Elasticsearch 的 @Karthick 所提到的 6.X 每个索引不止一种类型已被弃用,只有 _doc
内部和默认映射类型在版本 7 之前得到支持(出于向后兼容的目的),这也是将从即将发布的 8.X 主要版本中完全删除。
您需要删除自己的类型名称product
才能解决问题。
如official link why it's removed所述。
In an Elasticsearch index, fields that have the same name in different
mapping types are backed by the same Lucene field internally. In other
words, using the example above, the user_name field in the user type
is stored in exactly the same field as the user_name field in the
tweet type, and both user_name fields must have the same mapping
(definition) in both types.
This can lead to frustration when, for example, you want deleted to be
a date field in one type and a boolean field in another type in the
same index.
On top of that, storing different entities that have few or no fields
in common in the same index leads to sparse data and interferes with
Lucene’s ability to compress documents efficiently.
For these reasons, we have decided to remove the concept of mapping
types from Elasticsearch.
我已经在 spring 引导中实现了 Elasticsearch。每次重新启动服务器时,我都会收到以下错误。
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productController': Unsatisfied dependency expressed through field 'ps'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productServiceImpl': Unsatisfied dependency expressed through field 'pr'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productRepository': 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: Rejecting mapping update to [products] as the final mapping would have more than 1 type: [_doc, product]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
我每次启动服务器然后执行索引时都删除了索引。任何人都可以向我建议解决方案
Elasticsearch v6 及更高版本的每个索引不能有超过一种类型。但是从你的例外情况来看,你的映射试图在索引上创建多个类型(_doc 和产品)
参考https://www.elastic.co/guide/en/elasticsearch/reference/6.0/removal-of-types.html了解更多信息。
正如来自 Elasticsearch 的 @Karthick 所提到的 6.X 每个索引不止一种类型已被弃用,只有 _doc
内部和默认映射类型在版本 7 之前得到支持(出于向后兼容的目的),这也是将从即将发布的 8.X 主要版本中完全删除。
您需要删除自己的类型名称product
才能解决问题。
如official link why it's removed所述。
In an Elasticsearch index, fields that have the same name in different mapping types are backed by the same Lucene field internally. In other words, using the example above, the user_name field in the user type is stored in exactly the same field as the user_name field in the tweet type, and both user_name fields must have the same mapping (definition) in both types.
This can lead to frustration when, for example, you want deleted to be a date field in one type and a boolean field in another type in the same index.
On top of that, storing different entities that have few or no fields in common in the same index leads to sparse data and interferes with Lucene’s ability to compress documents efficiently.
For these reasons, we have decided to remove the concept of mapping types from Elasticsearch.