簡體   English   中英

Elasticsearch-groovy 索引模板

[英]Elasticsearch-groovy index template

有沒有辦法用elasticsearch-groovy或elasticsearch-java的API定義索引模板? 我想在其上應用“設置”(自定義分析器)和“映射”(在字段上應用分析器)。 文檔僅涉及索引模板x,但沒有顯示一個有效的示例,即如何在常規閉包中應用它們。 文檔中顯示的示例在數據(源)字段中添加了“設置”。

編輯:@Val 感謝您的回復,但如果我使用source字段如下:

    def templateR = client.admin.indices.putTemplate {
        name "template_name"
        source {
            template "template_*"         
        }
    }.actionGet()

... 這會導致編譯器錯誤: MissingMethodException No signature of method: ...source() 以下代碼:

    def templateR = client.admin.indices.putTemplate {
        name "lemato_template"
        template "lemato_*"
        settings {
            number_of_shards= 1      
        }            
    }.actionGet() 

給了我編譯器錯誤No such property: number_of_shards 我不確定我是否正確使用了閉包委托 是否缺少.asMap()類的東西?

elasticsearch-groovy 絕對支持創建/刪除索引模板。 source閉包可能包含您可以為索引模板定義的任何內容。 像這樣的事情應該有效。

PutIndexTemplateResponse response = client.admin.indices.putTemplate {
  name "my_template"
  source {
    template "index_*"
    settings {
      index {
        number_of_shards = 5
        number_of_replicas = 1
      }
    }
    mappings {
       // your mapping definitions
    }
    aliases {
       // your aliases
    }
  }
}.actionGet()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM