Hello, I annotate a field of an @Indexed class with two analyzers.
@Field(store = Store.YES, analyzer = @Analyzer(definition = "phonetic"))
@Field(store = Store.YES, analyzer = @Analyzer(definition = "ngram"))
private String value;
Now I use following query:
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
Query query = fullTextEntityManager.getSearchFactory()
.buildQueryBuilder()
.forEntity(itemClass)
.get()
.keyword()
.onField("value")
.matching(value)
.createQuery();
FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery(query);
fullTextQuery.setProjection(
ProjectionConstants.ID,
ProjectionConstants.OBJECT_CLASS,
ProjectionConstants.SCORE,
"value"
);
List<Object[]> resultList = fullTextQuery.getResultList();
When I use Lucene as backend it works. When I use Elasticsearch as backend i get following exception:
Caused by: java.lang.IllegalStateException
at com.google.gson.JsonArray.getAsString(JsonArray.java:226)
at org.hibernate.search.elasticsearch.query.impl.PrimitiveProjection.addDocumentField(PrimitiveProjection.java:69)
at org.hibernate.search.elasticsearch.query.impl.PrimitiveProjection.addDocumentField(PrimitiveProjection.java:43)
at org.hibernate.search.elasticsearch.query.impl.TwoWayFieldBridgeProjection.convertFieldValue(TwoWayFieldBridgeProjection.java:60)
at org.hibernate.search.elasticsearch.query.impl.TwoWayFieldBridgeProjection.convertHit(TwoWayFieldBridgeProjection.java:43)
at org.hibernate.search.elasticsearch.query.impl.QueryHitConverter.convert(QueryHitConverter.java:186)
at org.hibernate.search.elasticsearch.query.impl.IndexSearcher.convertQueryHit(IndexSearcher.java:138)
at org.hibernate.search.elasticsearch.query.impl.ElasticsearchHSQueryImpl.queryEntityInfos(ElasticsearchHSQueryImpl.java:233)
at org.hibernate.search.query.hibernate.impl.FullTextQueryImpl.doHibernateSearchList(FullTextQueryImpl.java:240)
at org.hibernate.search.query.hibernate.impl.FullTextQueryImpl.list(FullTextQueryImpl.java:225)
at org.hibernate.search.query.hibernate.impl.FullTextQueryImpl.getResultList(FullTextQueryImpl.java:124)
Breakpointing in com.google.gson.JsonArray.getAsString(JsonArray.java:226) it turns out that this.elements has size of 2. When I add a third @Field annotation, this.elements is 3. When I remove a field, this.elements is 1 and it works. Kind regards |