jordansissel/jruby-elasticsearch — pull request #10 by untergeek (2013-12-10 23:59:57+00:00)
Title: New methods for template management

Examples inline:

# Initialize

```
# Initialize the client here...
@client = ElasticSearch::Client.new(options)
java_client = @client.instance_eval{@client}
```

# Get templates

```
# Get/Fetch Example
@logger.debug("Time to fetch all templates...")
gettemplates = ElasticSearch::GetIndexTemplatesRequest.new(java_client, "*")
result = gettemplates.execute
# Results of this come as a list, so we need to iterate through it
template_metadata_list = result.getIndexTemplates()
templates = []
i = 0
template_metadata_list.size().times do
templates[i] = template_metadata_list.get(i)
puts "templates[i]: " + templates[i].to_s
puts "templates[i].name(): #{templates[i].name()}"
puts "templates[i].template(): #{templates[i].template()}"
i += 1
end
```

# Delete a template

```
# Delete Example
@logger.debug("Time to delete a template...")
delete_template = ElasticSearch::DeleteIndexTemplateRequest.new(java_client, @template_name)
result = delete_template.execute
@logger.debug("Delete result:", :result => result.to_s)
@logger.info("Successfully deleted template ", :template_name => @template_name) if result.isAcknowledged()
```

# Insert/Put a template

```
# Insert/Put Example
@logger.debug("Time to insert a template...")
get_template_json
put_template = ElasticSearch::PutIndexTemplateRequest.new(java_client, @template_name, @template_json)
result = put_template.execute
@logger.debug("Insert result:", :result => result.to_s)
@logger.info("Successfully inserted template ", :template_name => @template_name) if result.isAcknowledged()
```