我正在尝试使用 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());hibernate search 希望您传递查询本身,而无需包装器 json 对象。请参阅示例 此处。因此,在您的情况下,您应该传递:
{
"query_string":{
"fields":[
"addresses.address_key"
],
"query":"3g5g36ee-45b0-4636-79fe-9aaf446b7ab6"
}
}
以上就是查询ElasticSearch时出现named_object_not_found_Exception的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号