在elasticsearch中,是否有办法显示文档中的哪个字段是“命中"? [英] In elasticsearch, is there a way to show which field in a document was the "hit"?
问题描述
使用elasticsearch搜索某些文档时,我想查看文档中哪个字段是将其标记为搜索结果的匹配项".有本地方法可以做到这一点,还是我需要在搜索客户端中做到这一点?
When searching some documents using elasticsearch, I'd like to see which field in the document was the "hit" that flagged it up as a search result. Is there a native way to do this, or do I need to do it in the search client?
例如:
GET /events/_search?q=nottingham
给我:
{//elided
{'hits'[
{'id':1,
'name': 'Some name',
'nicknames': ['Nottingham']
}]}}
从此示例中可以明显看出,昵称是匹配的,但是我可以让elasticsearch为我标记吗?
it's obvious from this example that the nickname matched, but can I get elasticsearch to flag that for me?
推荐答案
Elasticsearch可以在结果字段中查找并突出显示查询中的术语.参见 http://www.elasticsearch.org/guide/reference/api/search/highlighting.html 了解更多信息.从技术上讲,它与标记导致命中"的字段并不相同,但出于大多数实际目的,它还是很有用的.
Elasticsearch can find and highlight terms from your query in the result fields. See http://www.elasticsearch.org/guide/reference/api/search/highlighting.html for more information. Technically speaking, it's not the same as flagging fields that caused the "hit", but for most practical purposes, it's as useful.
这篇关于在elasticsearch中,是否有办法显示文档中的哪个字段是“命中"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!