named_object_not_found_exception while query ElasticSearch

v1uwarro  于 12个月前  发布在  ElasticSearch
关注(0)|答案(1)|浏览(176)

我正在尝试使用hibernateSearh 6查询ElasticSearch。以下是发送到ElasticSearch的JSON查询。根据这里的文档,它看起来很好:https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html

{"query":{"query_string":{"fields":["addresses.address_key"],"query":"3g5g36ee-45b0-4636-79fe-9aaf446b7ab6"}}}

字符串
但是,获取以下带有消息的异常:

org.hibernate.search.util.common.SearchException: HSEARCH400007: Elasticsearch request failed: HSEARCH400090: Elasticsearch response indicates a failure.
Request: POST /employee-read/_search with parameters {from=0, size=10, track_total_hits=true}
Response: 400 'Bad Request' from 'http://localhost:9200' with body 
{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "unknown query [query]",
        "line": 1,
        "col": 19
      }
    ],
    "type": "parsing_exception",
    "reason": "unknown query [query]",
    "line": 1,
    "col": 19,
    "caused_by": {
      "type": "named_object_not_found_exception",
      "reason": "[1:19] unknown field [query]"
    }
  },
  "status": 400
}


以下是实体:

@Indexed(index = "employee")
public class Employee {

  @FullTextField(name = "employee_key")
  private String employeeKey;

  @FullTextField(name = "first_name")
  private String firstName;
    
  @IndexedEmbedded(includeEmbeddedObjectId = true, includeDepth = 2)
  private Address addresses;
}

public class Address {
    
  @FullTextField(name = "address_key")
  private String addressKey;

  @FullTextField(name = "street_name")
  private String streetName;

}


下面是从Elastic获取数据的代码,其中predicateFunction为:(ElasticsearchSearchPredicateFactory f) -> f.fromJson(queryJson)

SearchSession searchSession = Search.session(entityManager);

            SearchResult<Employee> searchResult = searchSession.search(Employee.class)
                    .extension(ElasticsearchExtension.get())
                    .where(searchPredicateFactory -> {
                        return predicateFunction.apply(searchPredicateFactory);
                    })
                    .fetch(Math.toIntExact(page.getOffset()), page.getPageSize());

mxg2im7a

mxg2im7a1#

Hibernate Search期望你传递查询本身,而不传递 Package 器JSON对象。参见这里的一个例子。所以在你的例子中,你应该传递一个:

{
   "query_string":{
      "fields":[
         "addresses.address_key"
      ],
      "query":"3g5g36ee-45b0-4636-79fe-9aaf446b7ab6"
   }
}

字符串

相关问题