弹性搜索索引模板 [英] Elasticsearch-groovy index template

查看:130
本文介绍了弹性搜索索引模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法用elasticsearch-groovy或elasticsearch-java的API定义索引模板?我想在其上应用设置(定制分析器)和映射(在场上应用分析器)。 文档仅指index templatex但不显示一个vaild示例,如何将它们应用于groovy关闭。文档中显示的示例在数据(源)字段中添加了设置。



编辑:@Val感谢您的回复,但如果我使用来源字段如下:

  def templateR = client.admin.indices .putTemplate {
nametemplate_name
source {
templatetemplate_ *
}
} .actionGet()

...这导致编译器错误: MissingMethodException没有方法的签名:... source() code>。以下代码:

  def templateR = client.admin.indices.putTemplate {
namelemato_template
模板lemato_ *
设置{
number_of_shards = 1
}
} .actionGet()

给我编译器错误没有这样的属性:number_of_shards 。我不知道我是否使用封闭委员会a>正确。是否像 .asMap()缺少?

elasticsearch-groovy绝对支持创建/删除索引模板。 来源关闭可能包含您可以为索引模板。这样的事情应该有效。

  PutIndexTemplateResponse response = client.admin.indices.putTemplate {
namemy_template
source {
templateindex_ *
settings {
index {
number_of_shards = 5
number_of_replicas = 1
}
}
mappings {
//你的映射定义
}
aliases {
//你的别名
}
}
} .actionGet()


Is there any way to define an index template with the API of elasticsearch-groovy or elasticsearch-java? I want to apply "settings" (custom analyzers) and "mappings" (apply analyzer on fields) on it. The documentation only refers to index templatex but does not show a vaild example, how to apply them in a groovy closure. The example shown in the docs, adds the "settings" in the data (source) field.

edit: @Val Thank you for your reply, but if I use the source field as follows:

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

... this results in a compiler-error: MissingMethodException No signature of method: ...source(). The following code:

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

gives me the compiler error No such property: number_of_shards. I'm not sure if I use the closure delegation correctly. Is something like .asMap() missing?

解决方案

elasticsearch-groovy definitely provides support for creating/deleting index templates. The source closure may contain anything you can define for index templates. Something like this should work.

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

这篇关于弹性搜索索引模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆