func (c EConn) createBulkIS(typeStr string, configs []elasticBody) (*elastic.BulkService, error) {
	cfgType := filterByType(typeStr, configs)

	if len(cfgType) == 0 {
		return nil, fmt.Errorf("type '%s' not found in configuration files", typeStr)
	}
	bulkReq := c.Bulk().Index(cfgType[0].Index).Refresh(true)
	for _, cfg := range cfgType {
		bulkReq.Add(elastic.NewBulkIndexRequest().Index(cfg.Index).
			Type(cfg.Type).Id(cfg.ID).Doc(cfg.Source))
	}
	return bulkReq, nil
}
Example #2
0
func (c EConn) UpdateNode(node *uc.Node) error {
	now := time.Now()
	node.UpdatedAt = now
	currIndexName := c.indexName + now.Format(indexFormatString)
	bulkReq := c.Bulk().Index(currIndexName).Refresh(true)
	for _, cont := range node.Containers {
		cont.UpdateLastValue()
		for _, inter := range cont.NetworkInterfaces {
			for _, stat := range inter.NetworkStats {
				enetstat := convertToElasticNetStat(cont, inter, stat)
				enetstat.UpdatedAt = now
				bulkReq.Add(elastic.NewBulkIndexRequest().Index(currIndexName).
					Type(NodeTableName).Timestamp(enetstat.UpdatedAt.Format(time.RFC3339Nano)).Doc(enetstat))
			}
		}
	}
	_, err := bulkReq.Do()
	if err != nil {
		return err
	}
	return nil
}