Reputation: 902
I have implemented Elasticsearch in spring boot. On every server restart, I am getting the following error.
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]
I have deleted the index every time to start the server and then perform the index. Can anyone suggest to me what will the solution
Upvotes: 1
Views: 2097
Reputation: 32376
As mentioned @Karthick from Elasticsearch 6.X more than one type per index is deprecated and only _doc
internal and default mapping type is supported till version 7(for backward compatibility purpose) and that too will be completely removed from soon to be released 8.X major version.
You need to remove your own type name product
to solve the issue.
As mentioned in the 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.
Upvotes: 1
Reputation: 1437
Elasticsearch v6 and above cannot have more than one type per index. But from your exception, your mapping is trying to create more than one type on an index (_doc and product)
Refer https://www.elastic.co/guide/en/elasticsearch/reference/6.0/removal-of-types.html for more info.
Upvotes: 2