daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. type Member struct {
  2.    Name string `json:"name"`
  3.    URL  string `json:"url"`
  4. }
  5.  
  6. members = []Member{}
  7.  
  8. keyword := "r"
  9. indexName : "member"
  10. typeName := "_doc"
  11. size := 10
  12. ctx := context.Background()
  13.  
  14. searchSuggester := elastic.NewCompletionSuggester("data").Text(keyword).Field("suggest").Size(size)
  15. searchSource := elastic.NewSearchSource().Suggester(searchSuggester) searchResult, err := client.Search().Index(indexName).Type(typeName).SearchSource(searchSource).Do(ctx)
  16.  
  17. for _, ops := range searchResult.Suggest["data"] {  
  18.    for _, op := range ops.Options {  
  19.       if op.Source == nil {
  20.          continue  
  21.       }  
  22.       var member Member  
  23.       err := json.Unmarshal(*op.Source, &member)  
  24.       if err != nil {    
  25.          log.Println(err)
  26.          continue  
  27.       }  
  28.       members = append(members, member)  
  29.    }
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top