在弹性搜索2.3.3中,添加高亮显示不适用于has_child查询 [英] add highlight does not work with has_child query in Elasticsearch 2.3.3

查看:206
本文介绍了在弹性搜索2.3.3中,添加高亮显示不适用于has_child查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用hasChildQuery时,一切都可以正常工作。但是当我添加 addHighlightedField()方法时,它不起作用。以下是我的代码:

When I use hasChildQuery,everything works OK.But when I add addHighlightedField() method,it does not work.The following is my code:

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];

我想突出显示所有字段,如何实现?

I want to highlight all the field,how to achieve that?

推荐答案

这与git 问题在这里。
线程中提到的解决方法是在 highlight_query

This is related to the bug specified in the git issue here . The workaround as mentioned in the thread is to specify it in 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

In Java Client you should be able to achieve it via this api

这篇关于在弹性搜索2.3.3中,添加高亮显示不适用于has_child查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆