使用Elasticsearch的亮點功能,在Elasticsearch全部內容:突出了多值字段
"highlight": {
"fields": {
"tags": { "number_of_fragments": 0 }
}
}
隨着number_of_fragments: 0
,沒有碎片產生,但返回的字段的全部內容。這對短文本很有用,因爲文檔可以正常顯示,人們可以輕鬆掃描突出顯示的部分。
當文檔包含具有多個值的數組時,您如何使用它?
PUT /test/doc/1
{
"tags": [
"one hit tag",
"two foo tag",
"three hit tag",
"four foo tag"
]
}
GET /test/doc/_search
{
"query": {
"match": { "tags": "hit"}
},
"highlight": {
"fields": {
"tags": { "number_of_fragments": 0 }
}
}
}
現在我想什麼來顯示用戶:
1結果:
文件1,標記:
「一個打標籤」,「二foo標籤「,」三個熱門標籤「,」四個foo標籤「
不幸的是,這是查詢的結果:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.10848885,
"hits": [
{
"_index": "test",
"_type": "doc",
"_id": "1",
"_score": 0.10848885,
"_source": {
"tags": [
"one hit tag",
"two foo tag",
"three hit tag",
"four foo tag"
]
},
"highlight": {
"tags": [
"one <em>hit</em> tag",
"three <em>hit</em> tag"
]
}
}
]
}
}
如何使用這個去:
"tags": [
"one <em>hit</em> tag",
"two foo tag",
"three <em>hit</em> tag",
"four foo tag"
]
這還沒有?你是如何解決這個問題的?我有同樣的問題。 – vmeln 2016-02-19 13:41:28
根據[此問題](https://github.com/elastic/elasticsearch/issues/7416)此功能仍然丟失... – 2017-11-14 14:46:24