How to do create_or_update for elasticsearch?

I have a simple example:

var client = new elasticsearch.Client({
    host: 'localhost:9200'
});

  client.create({ index: 't1', type: 't2', id : id, body: row},function(err,results) {
            callback(err, results )
  })

If record is exist, result error: DocumentAlreadyExistsException. How to update record if record exist ?

Answer

Try client.index instead of client.create. Keep in mind that this will always completely replace your existing document with the given id.