Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
ElasticSearch client library for Go
Go
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.gitignore
.travis.yml
LICENSE
README.md
cluster.go
cluster_test.go
index.go
index_test.go
node.go
query_test.go
requests.go
requests_test.go
response.go
searcher.go
types.go

README.md

elasticsearch

This is an opinionated library for ElasticSearch in Go. Its opinions are:

  • Builders are bad: construct queries declaratively, using nested structures
  • Cleverness is bad: when in doubt, be explicit and dumb

Build Status

Usage

First, it helps to import the package with a short name (package alias).

import es "github.com/peterbourgon/elasticsearch"

Create a Cluster, which is an actively-managed handle to a set of nodes.

endpoints := []string{"http://host1:9200", "http://host2:9200"}
pingInterval, pingTimeout := 30*time.Second, 3*time.Second
c := es.NewCluster(endpoints, pingInterval, pingTimeout)

Construct queries declaratively, and fire them against the cluster.

q := es.QueryWrapper(
    es.TermQuery(es.TermQueryParams{
        Query: &es.Wrapper{
            Name:    "user",
            Wrapped: "kimchy",
        },
    }),
)

request := &es.SearchRequest{
    Params: es.SearchParams{
        Indices: []string{"twitter"},
        Types:   []string{"tweet"},
    },
    Query:   q,
}

response, err := c.Search(request)
if err != nil {
    // Fatal
}
fmt.Printf("got %d hit(s)", response.HitsWrapper.Total)
Something went wrong with that request. Please try again.