跟進這個問題.
我有一個動態模板,它將一個JSON Blob的文本復制到一個單一的文本欄位中,我想在該欄位上進行搜索并突出顯示匹配的內容。以下是我在ES 6.5上的完整代碼
DELETE /test
PUT /test?include_type_name=true
{
"設定"。{"number_of_shards": 1, "number_of_replicas": 1},
"映射": {
"_doc": {
"dynamic_templates": [
{
"full_name": {
"match_mapping_type": "string",
"path_match": "content.*",
"mapping": {
"型別": "text",
"copy_to": "content_text"
}
}
}
],
"屬性"。{
"content_text": {
"型別": "文本"
},
"內容": {
"型別": "物件",
"啟用": "true"
}
}
}
}
}
PUT /test/_doc/1?refresh=true
{
"內容"。{
"a": {
"b": {
"text": "42"
}
}
}
}
GET /test/_search
{
"查詢"。{
"匹配"。{
"content_text": "42"
}
},
"亮點": {
"欄位": {
"content_text": {}
}
}
}
回應不顯示突出顯示的content_text
{
"taken" : 0,
"timed_out" : false,
"_shards" : {
"總數" : 1,
"成功" : 1,
"跳過" : 0,
"失敗" : 0
},
"點擊率" : {
"總數" : 1,
"max_score" : 0.2876821,
"點擊率" : [
{
"_index" : "test",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.2876821,
"_source" : {
"內容": {
"a" : {
"b" : {
"text" : "42"
}
}
}
}
}
}
}
正如你所看到的,content_text欄位沒有突出顯示。它也根本不在回應中。我怎樣才能讓這個欄位的高亮顯示出來呢?
uj5u.com熱心網友回復:
這是一個棘手的問題,但是一旦你閱讀了下面的內容就會明白了。
根據關于突出顯示的官方檔案,欄位的實際內容需要存在于某個地方。因此,如果該欄位沒有被存盤(即映射沒有將store設定為true),實際的_source將被加載,并且相關欄位將從_source中提取。
在你的案例中,content_text欄位并不存在于_source檔案中(也就是說,它只是從content.*中存在的其他文本欄位中索引出來的),在映射中,store引數沒有設定為true(它默認為假)。
因此你只需將你的映射改為:
"content_text": {
"存盤": true,
"型別": "文本"
},
然后你的查詢將產生這樣的結果:
"highlight" : {
"content_text" : [
"<em>42</em>"
]
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/329576.html
標籤:
上一篇:用NEST中的映射進行批量更新
下一篇:哪一個字串是最長的
