2016-08-05 84 views
1

以前我是用ES 1.5 ElasticSearch2.0映射,所以我可以很容易地創建數百個層次結構映射如下:如何快速創建數百場

{ 
    "mapping": { 
    "country.*.population": { 
     "type": "int" 
    } 
    } 
} 

這意味着有父母提起國家在上百個國家類型爲int。

由於ES2.0不支持字段名稱中的點,所以在創建映射時我必須寫入百次映射。例如:

{ 
    "country": { 
    "properties": { 
     "usa": { 
     "properties": { 
      "population": { 
      "type": "int" 
      } 
     } 
     }, 
     "canada": { 
     "properties": { 
      "population": { 
      "type": "int" 
      } 
     } 
     } 
    } 
    } 
} 

對此有任何想法嗎?

回答

1

你可以在你的映射使用dynamic template,像這樣:

PUT index 
{ 
    "mappings": { 
    "type": { 
     "dynamic_templates": [ 
     { 
      "countries": { 
      "path_match": "country.*.population", 
      "mapping": { 
       "type":  "int" 
      } 
      } 
     } 
     ] 
    } 
    } 
} 
+0

哦,太累了,甚至忘了我用過:-)解決方案 – Jack