Пример #1
0
func (a *Appbase) addBulkCommand(msg *message.Msg) (*message.Msg, error) {
	id, err := msg.IDString("_id")
	if err != nil {
		id = ""
	}

	switch msg.Op {
	case message.Delete:
		bulkRequest := elastic.NewBulkDeleteRequest().Index(a.appName).Type(a.typename).Id(id)
		a.AddBulkRequestSize(bulkRequest)
		a.bulkService.Add(bulkRequest)
		break
	case message.Update:
		bulkRequest := elastic.NewBulkUpdateRequest().Index(a.appName).Type(a.typename).Id(id).Doc(msg.Data)
		a.AddBulkRequestSize(bulkRequest)
		a.bulkService.Add(bulkRequest)
		break
	default:
		bulkRequest := elastic.NewBulkIndexRequest().Index(a.appName).Type(a.typename).Id(id).Doc(msg.Data)
		a.AddBulkRequestSize(bulkRequest)
		a.bulkService.Add(bulkRequest)
		break
	}

	a.commitBulk(false)

	return msg, nil
}
Пример #2
0
func (es *ElasticSearch) AddToBulk(bulk *elastic.BulkService, table string, model interface{}, id string) {
	bulk.Add(elastic.NewBulkIndexRequest().Index(es.index).Type(table).Doc(model).Id(id))
}