| 33 | } |
| 34 | |
| 35 | func NewOperator(urls []string, username, password string) (c *Operator, err error) { |
| 36 | doer := LoggingHttpClient{ |
| 37 | c: http.Client{}, |
| 38 | } |
| 39 | esClient, err := elastic.NewSimpleClient( |
| 40 | elastic.SetHttpClient(doer), |
| 41 | elastic.SetURL(urls...), |
| 42 | elastic.SetBasicAuth(username, password), |
| 43 | elastic.SetSniff(false), |
| 44 | elastic.SetErrorLog(NewErrLogger())) |
| 45 | if err != nil { |
| 46 | return nil, err |
| 47 | } |
| 48 | c = &Operator{C: esClient} |
| 49 | return c, nil |
| 50 | } |
| 51 | |
| 52 | func (op *Operator) CreateIndex(ctx context.Context, indexName string, mapping string) (err error) { |
| 53 | log.Debugf("try to create index: %s", indexName) |