【问题标题】:Elasticsearch-groovy index templateElasticsearch-groovy 索引模板
【发布时间】:2015-08-10 22:46:22
【问题描述】:

有没有办法用elasticsearch-groovy或elasticsearch-java的API定义索引模板?我想在它上面应用“设置”(自定义分析器)和“映射”(在字段上应用分析器)。 documentation 仅指索引 templatex,但没有显示有效示例,即如何在 groovy 闭包中应用它们。文档中显示的示例在数据(源)字段中添加了“设置”。

编辑:@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。我不确定我是否正确使用了closure delegation。像.asMap() 这样的东西不见了吗?

【问题讨论】:

    标签: groovy elasticsearch


    【解决方案1】:

    elasticsearch-groovy 绝对支持创建/删除索引模板。 source 闭包可以包含您可以为 index templates 定义的任何内容。像这样的东西应该工作。

    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()
    

    【讨论】:

    • 有什么不工作吗?我该如何帮助解决这个问题?
    猜你喜欢
    • 2016-11-09
    • 1970-01-01
    • 2021-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多