[英]Returning the “search term” along with result - Elasticsearch
In the elasticsearch module I have built, is it possible to return the "input search term" in the search results ? 在我构建的elasticsearch模块中,是否可以在搜索结果中返回“输入搜索词”?
For example : 例如 :
GET /signals/_search
{
"query": {
"match": {
"focused_content": "stock"
}
}
}
This returns 这返回
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.057534903,
"hits": [
{
"_index": "signals",
"_type": "signal",
"_id": "13",
"_score": 0.057534903,
"_source": {
"username": "abc@abc.com",
"tags": [
"News"
],
"content_url": "http://www.wallstreetscope.com/morning-stock-highlights-western-digital-corporation-wdc-fibria-celulose-sa-fbr-ametek-inc-ame-cott-corporation-cot-graftech-international-ltd-gti/25375462/",
"source": null,
"focused_content": "Morning Stock Highlights: Western Digital Corporation (WDC), Fibria Celulose SA (FBR), Ametek Inc. (AME), Cott Corporation (COT), GrafTech International Ltd. (GTI) - WallStreet Scope",
"time_stamp": "2015-08-12"
}
}
]
}
Is it possible to have the input search term "stock" along with each of the results (like an additional JSON Key along with "content_url","source","focused_content","time_stamp") to identify which search term had brought that result ? 是否可以让输入的搜索词“ stock”与每个结果(例如附加的JSON Key以及“ content_url”,“ source”,“ focused_content”,“ time_stamp”)一起标识哪个搜索词带来了结果呢?
Thanks in Advance ! 提前致谢 !
All I can think of, would be using highlighting feature. 我所能想到的就是使用突出显示功能。 So it would bring back additional key
_highlight
and it would highlight things, that matched. 因此,它将带回其他键
_highlight
,并突出显示匹配的内容。
It won't bring exact matching terms, tho. 它不会带来完全匹配的术语。 You'd have to deal with them in your application.
您必须在应用程序中处理它们。 You could use pre/post tags functionality to wrap them up somehow specially, so your app could recognize that it was a match.
您可以使用前/后标签功能以某种方式专门包装它们,以便您的应用可以识别出这是匹配项。
You can use highlights on all fields, like @Evaldas suggested. 您可以在所有字段上使用突出显示,例如建议使用@Evaldas。 This will return the result along with the value in the field which matched, surrounded by customisable tags (default is
<em>
). 这将返回结果以及匹配字段中的值,并由可自定义标签包围(默认为
<em>
)。
GET /signals/_search
{
"highlight": {
"fields": {
"username": {},
"tags": {},
"source": {},
"focused_content": {},
"time_stamp": {}
}
},
"query": {
"match": {
"focused_content": "stock"
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.