![](/img/trans.png)
[英]Prefer matching search term in beginning of search result rather than in the end using elasticsearch
[英]Returning the “search term” along with result - Elasticsearch
在我构建的elasticsearch模块中,是否可以在搜索结果中返回“输入搜索词”?
例如 :
GET /signals/_search
{
"query": {
"match": {
"focused_content": "stock"
}
}
}
这返回
{
"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"
}
}
]
}
是否可以让输入的搜索词“ stock”与每个结果(例如附加的JSON Key以及“ content_url”,“ source”,“ focused_content”,“ time_stamp”)一起标识哪个搜索词带来了结果呢?
提前致谢 !
我所能想到的就是使用突出显示功能。 因此,它将带回其他键_highlight
,并突出显示匹配的内容。
它不会带来完全匹配的术语。 您必须在应用程序中处理它们。 您可以使用前/后标签功能以某种方式专门包装它们,以便您的应用可以识别出这是匹配项。
您可以在所有字段上使用突出显示,例如建议使用@Evaldas。 这将返回结果以及匹配字段中的值,并由可自定义标签包围(默认为<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.