![](/img/trans.png)
[英]Elasticsearch - Include fields in highlight excluded in _source
[英]Use highlight in ElasticSearch with _source:false
只是想知道。 是否可以在_source = false的索引上突出顯示ElasticSearch中的文本?
我的意思是我知道ES是否沒有文檔,但他無法進行突出顯示,但是有沒有辦法僅將ES用作突出顯示引擎,而不是帶有突出顯示的完整搜索引擎? (我在高亮查詢中提供了完整的文檔)
謝謝
我不認為有可能。
但是,您可以在搜索查詢和文檔上使用_analyze,然后比較標記以在代碼中突出顯示。
例如:
curl -XGET 'localhost:9200/test/_analyze?analyzer=snowball' -d 'some search query keywords'
{ “標記”:[{ “令牌”: “一些”, “start_offset”:0 “end_offset”:4, “類型”: “”, “位置”:1},{ “令牌”: “搜索”, “start_offset”:5 “end_offset”:11, “類型”: “”, “位置”:2},{ “標記”: “查詢”, “start_offset”:12, “end_offset”:17, “類型” : “”, “位置”:3},{ “標記”: “關鍵字”, “start_offset”:18, “end_offset”:26, “類型”: “”, “位置”:4}]}
curl -XGET'localhost:9200 / test / _analyze?analyzer = snowball'-d'$ document_text'
{ “標記”:..}
然后在文檔中查找那些標記匹配項,並且偏移量應為您提供文檔中正確的突出顯示位置。
{
"query": {
"query_string": {
"query": "**",
"fields["
sometext "]}},"
highlight {
"pre_tags": ["<em>"],
"post_tags[</em>"],
"order": "score",
"require_field_match": true,
"fields": {
"sometext": {
"fragment_size": 180,
"number_of_fragments": 1
}
}
}
}
如果默認情況下未禁用源,則可以:
{
"_source" : ["_id"],
"query": {
"match" : {
"attachment.content" : "Setup"
}
},
"highlight": {
"fields" : {
"attachment.content" : {}
}
}
}
您必須在_score
放入一些_score
。 它仍然返回有關找到的文檔的每個“元數據”:
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.2919385,
"hits": [
{
"_index": "test",
"_type": "_doc",
"_id": "xpto",
"_score": 0.2919385,
"_source": {},
"highlight": {
"attachment.content": [
"<em>Setup</em> the [GenericCommand.properties] file\n\nThe commands that ought to be recognized have to be defined"
]
}
}
]
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.