func esBulk(client *es.Client, in <-chan es.BulkableRequest) { ticker := time.NewTicker(*batchInterval) bulk := client.Bulk() for { select { case <-ticker.C: if bulk.NumberOfActions() != 0 { lr := logrus.WithField("ops", bulk.NumberOfActions()) resp, err := bulk.Do() if err == nil && !resp.Errors { lr.Info("bulk successful") bulk = client.Bulk() } else { lr.WithError(err).Warn("bulk failed") } } case issue, ok := <-in: if !ok { return } bulk.Add(issue) } } }
func showNodes(client *elastic.Client) error { info, err := client.NodesInfo().Do() if err != nil { return err } log.Printf("Cluster %q with %d node(s)", info.ClusterName, len(info.Nodes)) for id, node := range info.Nodes { log.Printf("- Node %s with IP %s", id, node.IP) } return nil }
func initIndices(client *elastic.Client) error { exists, err := client.IndexExists(IndexGeoFences).Do() if err != nil { return err } if !exists { log.Info("Creating Index for GeoFences.") mapping := `{ "settings":{ "number_of_shards":1, "number_of_replicas":0 }, "mappings":{ "geofence":{ "properties":{ "name":{ "type":"string" }, "radius":{ "type":"double" }, "center":{ "type":"geo_point" }, "owner": { "type": "string" } } } } }` createIndex, err := client.CreateIndex(IndexGeoFences).BodyString(mapping).Do() if err != nil { return err } if !createIndex.Acknowledged { return errors.New("Could not create Index for GeoFences") } } return nil }