Thank you for your feedback. The error message is confusing; I will change it and document the limitation. An explanation of what is happening: you are trying to get an instance of org.apache.lucene.analysis.Analyzer, which is a Lucene-specific type, while using the Elasticsearch integration, which basically just manipulates JSON and delegates most of the operations (including analyzers) to a remove server across the network. This cannot be done; there is no Analyzer instance in your application when you use the Elasticsearch application, and there never will be. Now about a solution... I see you only need the analyzer to use MultiFieldQueryParser in order to parse a query string. If that string is provided by your users, you may want to use "simple query string" queries. They provide more or less the same feature as MultiFieldQueryParser, but on the contrary to MultiFieldQueryParser they can be used in the Elasticsearch backend. In your case you will have to do something like this:
FullTextSession fullTextSession = org.hibernate.search.Search.getFullTextSession((Session) entityManager.getDelegate());
QueryBuilder queryBuilder = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Book.class).get();
QueryBuilder queryBuilder =
Analyzer analyzer = fullTextSession.getSearchFactory().getAnalyzer(AccountingStructure.class);
org.hibernate.search.jpa.FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search
.getFullTextEntityManager(entityManager);
org.apache.lucene.search.Query luceneQuery = MultiFieldQueryParser.parse(queryList, fieldList, analyzer);
Query luceneQuery = queryBuilder
.simpleQueryString()
.onFields("field1", "field2", ...)
.matching("my query")
.createQuery();
If you need to run multiple queries, you should do this multiple types and combine the query objects using a boolean junction: see "Combining queries" in the documentation. |