diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-09-29 12:46:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-29 12:46:30 -0700 |
commit | b84736e9b6401df0c6eeab9950bef09458a6aefd (patch) | |
tree | d9175208de3236db75a33879750a57b3000ba096 /vendor/gopkg.in/olivere/elastic.v5/README.md | |
parent | 8b9dbb86133ff0fd6002a391268383d1593918ca (diff) | |
download | chat-b84736e9b6401df0c6eeab9950bef09458a6aefd.tar.gz chat-b84736e9b6401df0c6eeab9950bef09458a6aefd.tar.bz2 chat-b84736e9b6401df0c6eeab9950bef09458a6aefd.zip |
Updating server dependancies. (#7538)
Diffstat (limited to 'vendor/gopkg.in/olivere/elastic.v5/README.md')
-rw-r--r-- | vendor/gopkg.in/olivere/elastic.v5/README.md | 96 |
1 files changed, 2 insertions, 94 deletions
diff --git a/vendor/gopkg.in/olivere/elastic.v5/README.md b/vendor/gopkg.in/olivere/elastic.v5/README.md index ececd2769..45b84dab8 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/README.md +++ b/vendor/gopkg.in/olivere/elastic.v5/README.md @@ -107,101 +107,9 @@ The client connects to Elasticsearch on `http://127.0.0.1:9200` by default. You typically create one client for your app. Here's a complete example of creating a client, creating an index, adding a document, executing a search etc. -```go -// Create a context -ctx := context.Background() - -// Create a client -client, err := elastic.NewClient() -if err != nil { - // Handle error - panic(err) -} - -// Create an index -_, err = client.CreateIndex("twitter").Do(ctx) -if err != nil { - // Handle error - panic(err) -} - -// Add a document to the index -tweet := Tweet{User: "olivere", Message: "Take Five"} -_, err = client.Index(). - Index("twitter"). - Type("tweet"). - Id("1"). - BodyJson(tweet). - Refresh("true"). - Do(ctx) -if err != nil { - // Handle error - panic(err) -} - -// Search with a term query -termQuery := elastic.NewTermQuery("user", "olivere") -searchResult, err := client.Search(). - Index("twitter"). // search in index "twitter" - Query(termQuery). // specify the query - Sort("user", true). // sort by "user" field, ascending - From(0).Size(10). // take documents 0-9 - Pretty(true). // pretty print request and response JSON - Do(ctx) // execute -if err != nil { - // Handle error - panic(err) -} - -// searchResult is of type SearchResult and returns hits, suggestions, -// and all kinds of other information from Elasticsearch. -fmt.Printf("Query took %d milliseconds\n", searchResult.TookInMillis) - -// Each is a convenience function that iterates over hits in a search result. -// It makes sure you don't need to check for nil values in the response. -// However, it ignores errors in serialization. If you want full control -// over iterating the hits, see below. -var ttyp Tweet -for _, item := range searchResult.Each(reflect.TypeOf(ttyp)) { - if t, ok := item.(Tweet); ok { - fmt.Printf("Tweet by %s: %s\n", t.User, t.Message) - } -} -// TotalHits is another convenience function that works even when something goes wrong. -fmt.Printf("Found a total of %d tweets\n", searchResult.TotalHits()) - -// Here's how you iterate through results with full control over each step. -if searchResult.Hits.TotalHits > 0 { - fmt.Printf("Found a total of %d tweets\n", searchResult.Hits.TotalHits) - - // Iterate through results - for _, hit := range searchResult.Hits.Hits { - // hit.Index contains the name of the index - - // Deserialize hit.Source into a Tweet (could also be just a map[string]interface{}). - var t Tweet - err := json.Unmarshal(*hit.Source, &t) - if err != nil { - // Deserialization failed - } - - // Work with tweet - fmt.Printf("Tweet by %s: %s\n", t.User, t.Message) - } -} else { - // No hits - fmt.Print("Found no tweets\n") -} - -// Delete the index again -_, err = client.DeleteIndex("twitter").Do(ctx) -if err != nil { - // Handle error - panic(err) -} -``` +An example is available [here](https://olivere.github.io/elastic/) -Here's a [link to a complete working example](https://gist.github.com/olivere/114347ff9d9cfdca7bdc0ecea8b82263). +Here's a [link to a complete working example for v3](https://gist.github.com/olivere/114347ff9d9cfdca7bdc0ecea8b82263). See the [wiki](https://github.com/olivere/elastic/wiki) for more details. |