当我使用 hasChildQuery 时,一切正常。但是当我添加 addHighlightedField()
方法时,它不起作用。以下是我的代码:
TermsLookupQueryBuilder terms = QueryBuilders.termsLookupQuery("uuid")
.lookupIndex("bropen_framework_core_security_user").lookupType("user").lookupId("5")
.lookupPath("uuids");
HasChildQueryBuilder bookNameQuery = QueryBuilders.hasChildQuery("process",
QueryBuilders.hasChildQuery("permission", terms));
SearchResponse searchResponse1 = client
.prepareSearch()
//.addHighlightedField("_all")
.setQuery(hasChildQuery)
.setPostFilter(QueryBuilders
.queryStringQuery(query.toString()))
.setFrom(0)
.setSize(1000)
.execute().actionGet();
异常信息:
RemoteTransportException[[node-224][192.168.0.224:9300] [indices:data/read/search[phase/fetch/id]]]; nested: FetchPhaseExecutionException[Fetch Failed [Failed to highlight
field [_all]]];
nested: IllegalStateException[can't load global ordinals for
reader of type: class
org.apache.lucene.search.highlight.WeightedSpanTermExtractor
$DelegatingLeafReader must be a DirectoryReader];
我想高亮所有字段,如何实现?
最佳答案
这与 git issue 中指定的错误有关这里 。
线程中提到的解决方法是在 highlight_query
示例:
PUT test
{
"mappings": {
"my_parent": {
"_all": {
"store": true
}
},
"my_child": {
"_parent": {
"type": "my_parent"
}
}
}
}
PUT test/my_parent/1
{
"text": "This is a parent document"
}
PUT test/my_child/2?parent=1
{
"text": "This is a child document"
}
POST test/my_parent/_search
{
"query": {
"bool": {
"must": [
{
"has_child": {
"type": "my_child",
"query": {
"match": {
"text": "child document"
}
}
}
},
{
"match": {
"_all": "parent"
}
}
]
}
},
"highlight": {
"fields": {
"_all": {}
},
"highlight_query": {
"match": {
"_all": "parent"
}
}
}
}
结果:
{
"_index": "test",
"_type": "my_parent",
"_id": "1",
"_score": 1.016466,
"_source": {
"text": "This is a parent document"
},
"highlight": {
"_all": [
"This is a <em>parent</em> document "
]
}
}
在 Java 客户端中,您应该可以通过此 api 实现它
关于elasticsearch - 添加突出显示不适用于 Elasticsearch 2.3.3 中的 has_child 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38886939/