当我使用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];
我想强调所有领域,如何实现这一目标?
答案 0 :(得分:2)
这与此处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
实现它