| 1 |
// Copyright 2012-present Oliver Eilhard. All rights reserved. |
| 2 |
// Use of this source code is governed by a MIT-license. |
| 3 |
// See http://olivere.mit-license.org/license.txt for details. |
| 4 |
|
| 5 |
/* |
| 6 |
Package elastic provides an interface to the Elasticsearch server |
| 7 |
(https://www.elastic.co/products/elasticsearch). |
| 8 |
|
| 9 |
The first thing you do is to create a Client. If you have Elasticsearch |
| 10 |
installed and running with its default settings |
| 11 |
(i.e. available at http://127.0.0.1:9200), all you need to do is: |
| 12 |
|
| 13 |
client, err := elastic.NewClient() |
| 14 |
if err != nil { |
| 15 |
// Handle error |
| 16 |
} |
| 17 |
|
| 18 |
If your Elasticsearch server is running on a different IP and/or port, |
| 19 |
just provide a URL to NewClient: |
| 20 |
|
| 21 |
// Create a client and connect to http://192.168.2.10:9201 |
| 22 |
client, err := elastic.NewClient(elastic.SetURL("http://192.168.2.10:9201")) |
| 23 |
if err != nil { |
| 24 |
// Handle error |
| 25 |
} |
| 26 |
|
| 27 |
You can pass many more configuration parameters to NewClient. Review the |
| 28 |
documentation of NewClient for more information. |
| 29 |
|
| 30 |
If no Elasticsearch server is available, services will fail when creating |
| 31 |
a new request and will return ErrNoClient. |
| 32 |
|
| 33 |
A Client provides services. The services usually come with a variety of |
| 34 |
methods to prepare the query and a Do function to execute it against the |
| 35 |
Elasticsearch REST interface and return a response. Here is an example |
| 36 |
of the IndexExists service that checks if a given index already exists. |
| 37 |
|
| 38 |
exists, err := client.IndexExists("twitter").Do(context.Background()) |
| 39 |
if err != nil { |
| 40 |
// Handle error |
| 41 |
} |
| 42 |
if !exists { |
| 43 |
// Index does not exist yet. |
| 44 |
} |
| 45 |
|
| 46 |
Look up the documentation for Client to get an idea of the services provided |
| 47 |
and what kinds of responses you get when executing the Do function of a service. |
| 48 |
Also see the wiki on Github for more details. |
| 49 |
|
| 50 |
*/ |
| 51 |
package elastic |