@Configuration
@PropertySource({"classpath:manager-database.properties"/*, "classpath:hibernate.properties"*/})
@EnableJpaRepositories(basePackages = {"org.taharb.manager.web.dao"},
entityManagerFactoryRef = "managerEntityManager",
transactionManagerRef = "managerTransactionManager")
public class ManagerDatabase {
private final Environment environment;
@Autowired
public ManagerDatabase(Environment environment) {
this.environment = environment;
}
@Bean
public LocalContainerEntityManagerFactoryBean managerEntityManager() {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(managerDataSource());
entityManagerFactoryBean.setPackagesToScan(new String[]{"org.taharb.manager.web.model"});
entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
Properties properties = new Properties();
try {
properties.load(ManagerDatabase.class.getClassLoader().getResourceAsStream("hibernate.properties"));
} catch (Exception e) {
}
entityManagerFactoryBean.setJpaProperties(properties);
return entityManagerFactoryBean;
}
@Bean
public DataSource managerDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(environment.getProperty("manager.jdbc.driverClassName"));
dataSource.setUrl(environment.getProperty("manager.jdbc.url"));
dataSource.setUsername(environment.getProperty("manager.jdbc.username"));
dataSource.setPassword(environment.getProperty("manager.jdbc.password"));
return dataSource;
}
@Bean
public PlatformTransactionManager managerTransactionManager() {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(managerEntityManager().getObject());
return transactionManager;
}
}
and Finaly the search service
@Service
public class ClientSearch {
private final EntityManagerFactory entityManagerFactory;
@Autowired
public ClientSearch(@Qualifier("managerEntityManager") EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory;
}
public List<Client> searchByKeyword(final String keyword) {
EntityManager entityManager = entityManagerFactory.createEntityManager();
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Client.class).get();
return fullTextEntityManager
.createFullTextQuery(queryBuilder.keyword()
.onFields("firstName", "lastName")
.matching(keyword)
.createQuery(), Client.class).getResultList();
}
}
So when i try to start the application i get this error
2017-10-23 23:06:09.505 ERROR 13452 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'managerEntityManager' defined in class path resource [org/taharb/manager/configuration/ManagerDatabase.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078) ~[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857) ~[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
at org.taharb.manager.configuration.Application.main(Application.java:12) [classes/:na]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:882) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370) ~[spring-orm-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359) ~[spring-orm-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
... 16 common frames omitted
Caused by: org.hibernate.search.exception.SearchException: HSEARCH400020: Could not create mapping for entity type org.taharb.manager.web.model.Client
at org.hibernate.search.elasticsearch.schema.impl.ElasticsearchSchemaAccessor.putMapping(ElasticsearchSchemaAccessor.java:235) ~[hibernate-search-elasticsearch-5.6.3.Final.jar:5.6.3.Final]
at org.hibernate.search.elasticsearch.schema.impl.DefaultElasticsearchSchemaCreator.createMappings(DefaultElasticsearchSchemaCreator.java:88) ~[hibernate-search-elasticsearch-5.6.3.Final.jar:5.6.3.Final]
at org.hibernate.search.elasticsearch.impl.ElasticsearchIndexManager.initializeIndex(ElasticsearchIndexManager.java:298) ~[hibernate-search-elasticsearch-5.6.3.Final.jar:5.6.3.Final]
at org.hibernate.search.elasticsearch.impl.ElasticsearchIndexManager.initializeIndex(ElasticsearchIndexManager.java:254) ~[hibernate-search-elasticsearch-5.6.3.Final.jar:5.6.3.Final]
at org.hibernate.search.elasticsearch.impl.ElasticsearchIndexManager.setSearchFactory(ElasticsearchIndexManager.java:245) ~[hibernate-search-elasticsearch-5.6.3.Final.jar:5.6.3.Final]
at org.hibernate.search.indexes.impl.IndexManagerHolder.setActiveSearchIntegrator(IndexManagerHolder.java:195) ~[hibernate-search-engine-5.6.3.Final.jar:5.6.3.Final]
at org.hibernate.search.engine.impl.MutableSearchFactoryState.setActiveSearchIntegrator(MutableSearchFactoryState.java:230) ~[hibernate-search-engine-5.6.3.Final.jar:5.6.3.Final]
at org.hibernate.search.spi.SearchIntegratorBuilder.buildNewSearchFactory(SearchIntegratorBuilder.java:230) ~[hibernate-search-engine-5.6.3.Final.jar:5.6.3.Final]
at org.hibernate.search.spi.SearchIntegratorBuilder.buildSearchIntegrator(SearchIntegratorBuilder.java:120) ~[hibernate-search-engine-5.6.3.Final.jar:5.6.3.Final]
at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:75) ~[hibernate-search-orm-5.6.3.Final.jar:5.6.3.Final]
at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:35) ~[hibernate-core-5.1.7.Final.jar:5.1.7.Final]
at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:521) ~[hibernate-core-5.1.7.Final.jar:5.1.7.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:465) ~[hibernate-core-5.1.7.Final.jar:5.1.7.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
... 22 common frames omitted
Caused by: org.hibernate.search.exception.SearchException: HSEARCH400007: Elasticsearch request failed.
Request:
========
Operation: PutMapping
URI:client_index/org.taharb.manager.web.model.Client/_mapping
Data:
{
"properties": {
"birthDate": {
"type": "date",
"boost": 1.0,
"index": "not_analyzed",
"store": false
},
"firstName": {
"type": "string",
"boost": 1.0,
"index": "analyzed",
"store": false,
"analyzer": "default"
},
"id": {
"type": "string",
"boost": 1.0,
"index": "not_analyzed",
"store": true
},
"lastName": {
"type": "string",
"boost": 1.0,
"index": "analyzed",
"store": false,
"analyzer": "default"
}
},
"dynamic": "strict"
}
Response:
=========
Status: 400
Error message: {"root_cause":[{"type":"illegal_argument_exception","reason":"The [string] type is removed in 5.0 and automatic upgrade failed because parameters [boost] are not supported for automatic upgrades. You should now use either a [text] or [keyword] field instead for field [firstName]"}],"type":"illegal_argument_exception","reason":"The [string] type is removed in 5.0 and automatic upgrade failed because parameters [boost] are not supported for automatic upgrades. You should now use either a [text] or [keyword] field instead for field [firstName]"}
Cluster name: null
Cluster status: 400
at org.hibernate.search.elasticsearch.impl.DefaultBackendRequestResultAssessor.checkSuccess(DefaultBackendRequestResultAssessor.java:94) ~[hibernate-search-elasticsearch-5.6.3.Final.jar:5.6.3.Final]
at org.hibernate.search.elasticsearch.client.impl.JestClient.executeRequest(JestClient.java:183) ~[hibernate-search-elasticsearch-5.6.3.Final.jar:5.6.3.Final]
at org.hibernate.search.elasticsearch.client.impl.JestClient.executeRequest(JestClient.java:176) ~[hibernate-search-elasticsearch-5.6.3.Final.jar:5.6.3.Final]
at org.hibernate.search.elasticsearch.schema.impl.ElasticsearchSchemaAccessor.putMapping(ElasticsearchSchemaAccessor.java:232) ~[hibernate-search-elasticsearch-5.6.3.Final.jar:5.6.3.Final]
... 35 common frames omitted
Hello everybody,
I am trying to configure hibernate search with spring boot data jpa and elastic-search, so this my confs
My model is this one
hibernate.properties
My Config Class
and Finaly the search service
So when i try to start the application i get this error
Please any help to solve this, Thank you Regards