Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Snapshot Repository API #508

Merged
merged 1 commit into from
Apr 10, 2017
Merged

Add Snapshot Repository API #508

merged 1 commit into from
Apr 10, 2017

Conversation

Flygsand
Copy link
Contributor

@Flygsand Flygsand commented Apr 7, 2017

This PR adds support for Elasticsearch's snapshot repository API.

Example program:

package main

import (
	"context"
	"fmt"

	elastic "gopkg.in/olivere/elastic.v5"
)

type FSSettings struct {
	Location string `json:"location"`
}

func main() {
	client, err := elastic.NewClient()
	if err != nil {
		panic(err)
	}

	repo := new(elastic.SnapshotRepository)
	repo.Type = "fs"
	settings := new(FSSettings)
	settings.Location = "/tmp/elasticsearch"
	repo.Settings = settings

	_, err = client.SnapshotCreateRepository("repo1").BodyJson(repo).Do(context.TODO())
	if err != nil {
		panic(err)
	}

	repos, err := client.SnapshotGetRepository("repo1").Do(context.TODO())
	if err != nil {
		panic(err)
	}
	fmt.Printf("%v\n", repos)

	verify, err := client.SnapshotVerifyRepository("repo1").Do(context.TODO())
	if err != nil {
		panic(err)
	}
	fmt.Printf("%v\n", verify.Nodes)

	_, err = client.SnapshotDeleteRepository("repo1").Do(context.TODO())
	if err != nil {
		panic(err)
	}
}

@olivere
Copy link
Owner

olivere commented Apr 7, 2017

Awesome. Thanks for sharing. Would definitely like to add this to elastic!

I build the services from the REST API specification. There's even a code generator in the generate-api branch. Did you use that to create the skeleton of the services?

@Flygsand
Copy link
Contributor Author

Flygsand commented Apr 7, 2017

That would explain why some of the code had a generation feel to it :). No, I was not aware of this workflow. Copy-pasted together most of it. Anyway, ran the generator and updated the PR.

@olivere olivere merged commit 10be2b8 into olivere:release-branch.v5 Apr 10, 2017
olivere added a commit that referenced this pull request Apr 10, 2017
You can now build the body via the builder.

See #508
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants