返回弹性搜索中匹配的字段 [英] Return which field got matched in Elastic Search
问题描述
我正在尝试查找与返回的文档具体匹配的搜索内容.
I am trying to find out what actually got matched for a search in a specific for which the doc is returned.
例如我有一个表索引,其中有名为table_name和column_name的字段...我的搜索查询正在查找这两个字段,现在,如果我触发搜索查询,并且其中任何一个都被匹配,但我想知道匹配的是什么..无论是column_name还是table_name.
Ex. I have a table index where there are fields called table_name and column_name... My search query is finding both those fields, now If I fire a search query and any one of them gets matched ,but I want to know what got matched .. whether its column_name or the table_name.
我知道Explain API,但这将要求我调用另一个API ...
I am aware of the Explain API but that will require me to call another API...
推荐答案
您无需调用说明API.搜索API支持 explain
标志
You don't need to call the explain API. The search API supports the explain
flag
GET stackoverflow/_search?explain=true
这将返回 _explanation
部分以及 _source
部分.
This will return the _explanation
section along with the _source
section.
更新
另一种解决方案是使用突出显示.我以前曾用它来手动评估查询.这是一种获取有关匹配项的反馈的简单方法
Another solution would be to use highlight. I've used this before, for manually evaluating queries. It's an easy way to get some feedback on what matched
GET stackoverflow/_search
{
"query": {
"match": {
"FIELD": "TEXT"
}
},
"highlight": {
"fields": {
"*": {}
}
}
}
当然,您也可以设置解释标志
Of course, you can have the explain flag set as well
这篇关于返回弹性搜索中匹配的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!