elasticsearch - 添加突出显示不适用于 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];

我想高亮所有字段,如何实现?

最佳答案

这与 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/

相关文章:

laravel - 如何在AWS Elastic Search中进行批量索引

elasticsearch - Logstash 提取嵌套字段并将其移动到新的父字段中

elasticsearch - 用于Elasticsearch的自定义 token 过滤器

elasticsearch - grok 不读带连字符的单词

elasticsearch - 带有过滤器的日期直方图聚合问题

java - SpringData Elasticsearch JSON 数组到 Java 列表

Python从elasticsearch中获取 float 作为 float 数组

elasticsearch - 通过 Elasticsearch 从具有相同值的字段中获取所有文档

symfony - FOSElasticaBundle 未填充 AWS ElasticSearch 中的 searchableDocuments

elasticsearch - Searchkick::ImportError尝试重新索引时