一尘不染

在Elasticsearch 2.3.3中添加突出显示不适用于has_child查询

elasticsearch

当我使用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];

我想强调所有领域,如何实现?


阅读 378

收藏
2020-06-22

共1个答案

一尘不染

这与git
问题中指定的错误有关。线程中提到的解决方法是在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
Client中,您应该可以通过此api实现它

2020-06-22