2016-02-19 32 views
0

我正在映射一個couchbase網關文檔,我想告訴elasticsearch避免索引由網關添加的內部屬性,如「_sync」,該對象包含另一個名爲「channels」的對象,其格式如下:如何在elasticsearch中映射動態字段值?

"channels": { 
    "i7de5558-32ad-48ca-bf91-858c3a1e4588": 12 
} 

所以我想這個對象的映射是這樣的:

"channels": { 
    "type": "object", 
    "properties": { 
     "i7de5558-32ad-48ca-bf91-858c3a1e4588": { 
      "type": "integer", 
      "index": "not_analyze" 
     } 
    } 
} 

的問題是,按鍵總是在不斷變化,所以我不知道我是否應該使用通配符這樣的「 *「:{」type「:」integer「,」index「:」not_analyze「}或者做其他事情。 有什麼建議嗎?

回答

1

如果這些字段是整數類型的,你不必在映射中明確地提供它們。您可以創建一個空映射,索引具有這些字段的文檔。 Elasticsearch將推斷字段的類型並動態更新映射。您也可以使用dynamic templates

{ 
"mappings": { 
    "my_type": { 
    "dynamic_templates": [ 
     { 
      "analysed_string_template": { 
       "path_match": "channels.*", 
       "mapping": { 
       "type": "integer" 
       } 
      } 
     } 
    ] 
    } 
    } 
} 
+0

非常感謝,這沒有把戲。 – onizukaek

0

那裏`s動態的方式做到這一點,因爲你需要,被稱爲dynamic template

使用模板,你能這樣創建規則:

PUT /my_index 
{ 
    "mappings": { 
     "my_type": { 
      "date_detection": false 
     } 
    } 
} 

你的情況,你可以創建一個模板將通道對象內的所有新聞字段設置爲not_analyze。 希望它能幫到

相關問題