I've got the following configuration inside spring application:
@Configuration
public class config {
@Bean
public TransportClient elasticsearchSecuredClient() throws Exception {
// Based on https://github.com/elastic/found-shield-example/blob/master/src/main/java/org/elasticsearch/cloud/transport/example/TransportExample.java
Settings settings = Settings.builder().build();
XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().
startObject().
startObject("mappings").
startObject("restaurant").
startObject("properties").
startObject("amount").field("type", "long").endObject().
endObject().
field("dynamic", "strict").
endObject().
endObject().
endObject();
TransportClient localhost = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress("localhost", 9300)));
localhost.admin().indices().prepareCreate("expenses").addMapping("restaurant",xContentBuilder).get();
return localhost;
}
}
This is my entity :
@Data
@Document(indexName = "expenses",type = "restaurant")
public class ResturantExpenseEntity {
//@Id
//private String id;
@Id
private Long amount;
}
and this is the stacktrace of the error :
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'hello': Unsatisfied dependency expressed through field 'repo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resturantExpensesRepo': Cannot resolve reference to bean 'elasticsearchTemplate' while setting bean property 'elasticsearchOperations'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'elasticsearchTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchSecuredClient' defined in class path resource [hello/config.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.transport.TransportClient]: Factory method 'elasticsearchSecuredClient' threw exception; nested exception is MapperParsingException[Failed to parse mapping [restaurant]: Root mapping definition has unsupported parameters: [mappings : {restaurant={dynamic=strict, properties={amount={type=long}}}}]]; nested: MapperParsingException[Root mapping definition has unsupported parameters: [mappings : {restaurant={dynamic=strict, properties={amount={type=long}}}}]]; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:581) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE] at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:367) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1340) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:756) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) ~[spring-context-5.0.1.RELEASE.jar:5.0.1.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.0.1.RELEASE.jar:5.0.1.RELEASE]
or in short, the error states that : Root mapping definition has unsupported parameters: [mappings : {restaurant={dynamic=strict, properties={amount={type=long}}}}]];
what am i doing wrong ? I tried also with @Mapping annotation and giving a path for a json file with the same mapping, and i get the same result !
Please help :) Thanks