无法使Elasticsearch Highlight正常工作 [英] Cannot get Elasticsearch Highlight to work

查看:115
本文介绍了无法使Elasticsearch Highlight正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事一个涉及Elasticsearch的项目.到目前为止,除高亮显示之外,我可以使用大多数功能.我正在使用Laravel + Elasticsearch官方PHP客户端.

I am working on a project that involves Elasticsearch. So far I can get most function to work except highlight. I am using Laravel + Elasticsearch official PHP client.

以前,我认为这是我的PHP代码的问题,并在这里提出了一个问题: Elasticsearch结果,PHP中缺少突出显示的字段

Previously I thought it was a problem of my PHP code, and asked a question here: highlight field missing from Elasticsearch results, PHP

稍后,当我在浏览器中尝试使用elasticsearch-head时,仍然看不到结果中的突出显示字段,因此我想我的Elasticsearch设置或索引文档的方式都一定有问题.

Later when I tried with elasticsearch-head in browser, I still cannot see highlight field in results, so I guess there must be something wrong with either my settings of elasticsearch or the way I indexed the documents.

这是我在elasticsearch-head中输入的查询:

Here is the query I entered into elasticsearch-head:

{
"query" : {
    "match" : {
        "combined" : "DNA"
    }
},
"highlight": {
    "fields" : {
        "combined" : {}
    }
}
}

elasticsearch返回的匹配中,"_ source"后面没有突出显示".

And I don't see "highlight" after "_source" in hits returned by elasticsearch.

我在这里可能做错了什么?

What might I did wrong here?

请告知,

谢谢.

更新:我正在Ubuntu 16.04 LTS桌面,JDK 1.8上运行Elasticsearch 2.3.3.

Update: I'm running Elasticsearch 2.3.3, on Ubuntu 16.04 LTS desktop, JDK 1.8.

文档说映射中的存储"需要设置为true.我这样做了,然后重新索引了一堆文件.这不能解决问题.

Documentation says "store" in mapping needs to be set true. I did so, and re-indexed a bunch of documents. This didn't fix the problem.

推荐答案

好的,在停止并重新启动Elasticsearch服务之后,我的代码开始按预期工作.我在结果中看到突出显示"字段.

OK, after stopping and restarting elasticsearch service, my code started to work as intended. I got "highlight" field in results.

问题是我需要将"store"设置为true.其他所有条件都相同,包括以下行

The issue is that I need to set "store" to true. Everything else being equal, including the following line

"store"   =>   true

在映射中确保突出显示"出现在我得到的结果中.反之亦然.

in mapping ensured "highlight" appear in the results I have. Vice versa.

不确定为什么早些这样做不能解决我的问题.

Not sure why doing this earlier didn't solve my problem.

这篇关于无法使Elasticsearch Highlight正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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