gson ElasticSearch出现意外的JSON元素类型异常

xienkqul  于 2022-11-06  发布在  ElasticSearch
关注(0)|答案(1)|浏览(163)

ElasticSearch提供了以下异常:

WARNING: request [POST http://localhost:9200/domain.dog/_search?size=10000&from=0] returned 1 warnings: [299 Elasticsearch-7.11.2-3e5a16cfec50876d20ea77b075070932c6464c7d "[types removal] Type queries are deprecated, prefer to filter on a field instead."]

org.hibernate.search.elasticsearch.gson.impl.UnexpectedJsonElementTypeException: Unexpected type at '.hits(JsonObject).total(JsonPrimitive(Integer))'. Expected one of [JsonPrimitive(Integer)], got '{"value":1,"relation":"eq"}'
    at org.hibernate.search.elasticsearch.gson.impl.TypingJsonAccessor.fromElement(TypingJsonAccessor.java:55)
    at java.base/java.util.Optional.map(Optional.java:265)
    at org.hibernate.search.elasticsearch.gson.impl.TypingJsonAccessor.get(TypingJsonAccessor.java:31)
    at org.hibernate.search.elasticsearch.gson.impl.JsonIntegerAccessorImpl.get(JsonIntegerAccessorImpl.java:14)
    at org.hibernate.search.elasticsearch.work.impl.SearchWork$SearchResultImpl.getTotalHitCount(SearchWork.java:147)
    at org.hibernate.search.elasticsearch.query.impl.ElasticsearchHSQueryImpl.execute(ElasticsearchHSQueryImpl.java:269)
    at org.hibernate.search.elasticsearch.query.impl.ElasticsearchHSQueryImpl.queryEntityInfos(ElasticsearchHSQueryImpl.java:226)
    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 threadTest.ThreadTest.search(ThreadTest.java:235)
    at threadTest.ThreadTest.access$0(ThreadTest.java:224)
    at threadTest.ThreadTest$1ListDogs.run(ThreadTest.java:127)
    at java.base/java.lang.Thread.run(Thread.java:834)

使用休眠搜索
是什么原因导致的?
编辑:这是我正在使用的代码:

EntityManager em = emf.createEntityManager();
        Session session = em.unwrap(org.hibernate.Session.class);
        FullTextSession fullTextSession = Search.getFullTextSession(session);

        QueryBuilder queryBuilder = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Dog.class).get();
        org.apache.lucene.search.Query luceneQuery = queryBuilder.keyword().onFields("id").matching("1").createQuery();

        // wrap Lucene query in a javax.persistence.Query
        org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery(luceneQuery, Dog.class);

        List<Dog> contactList = fullTextQuery.list();

        fullTextSession.close();

        em.close();
deyfvvtc

deyfvvtc1#

它变得非常简单,只需为我正在使用的Hibernate OGM版本使用正确的ElasticSearch版本即可。
[休眠搜索参考指南][1] https://docs.jboss.org/hibernate/search/5.11/reference/en-US/html_single/#_getting_started_and_configuration

相关问题