2016-03-15 42 views
1

例如,我想創建基於時間的索引。在彈性搜索中,我們可以通過創建一個模式來實現。如何使用彈簧數據在elasticsearch中創建動態模板。

curl -XPUT 'localhost:9200/_template/indextemplate' -d '{ 
     "template": "dynamicIndex-*", 
     "order": 0, 
     "settings": { 
     "index": { 
      "number_of_shards": 2, 
      "number_of_replicas": 2 
     } 
     } 
    } 

在上例中,設置和映射將應用於「dynamicIndex-」。所以現在我可以創建像dynamicIndex-1,dyanmicIndex-2這樣的每週索引。 如何使用彈簧數據實現這一點(如何使用彈簧數據創建/設置索引模板)。

+0

與定義與彈簧數據elasticsearch動態模板任何運氣? –

+0

https://github.com/spring-projects/spring-data-elasticsearch/pull/132#issuecomment-254476072現在添加動態模板註釋。 –

回答

1

可以使用PutIndexTemplateRequest在elasticsearch創建模板,使用Java客戶端。這將創建一個通用模板,該模板將應用於模板源文件中指定的所有索引。

`

source = readFile(templatePath, StandardCharsets.UTF_8); 
    PutIndexTemplateRequest request = new PutIndexTemplateRequest("template-name"); 
    request.source(source.getBytes()); 
    PutIndexTemplateResponse response = client.admin().indices().execute(PutIndexTemplateAction.INSTANCE, request) 
     .get(); 

    if (!response.isAcknowledged()) { 
    LOGGER.error("Error While Updating Template"); 
    } else { 
    LOGGER.debug("Template Updated Successfully on the elasticsearch"); 
    } 

`

相關問題