From within a C# winform application I am writing to elasticsearch which is working successfully. This is fine for my audit process but there is a requirement to write notes data to elasticsearch to enable text searching. Previously this data was stored in a MySQL database and updating notes record was straight forward by using the SQL query below but I struggling to find an elasticsearch equivalent as just indexing a document creates multiple entries for the same id.
UPDATE table SET details = 'updated details' WHERE id = '1';
All data is written using the following structure:
public class TestNotesRecord
{
public int TestNotes_Id { get; set; }
public DateTime TestNotes_DateTime { get; set; }
public string TestNotes_UserId { get; set; }
public string TestNotes_Details { get; set; }
}
Then this is written to elasticsearch using this function:
public bool SaveTestNotes(TestNotesRecord thisRecord, ref string message)
{
bool success = true;
// Connect to Elastic Search
string elasticStatus = "";
var uri = new Uri(ElasticHost);
var settings = new ConnectionSettings(uri);
try
{
settings.ThrowExceptions(alwaysThrow: true);
settings.PrettyJson();
Client = new ElasticClient(settings);
var response = Client.Cluster.Health();
elasticStatus = response.Status.ToString();
settings.DefaultIndex("testnotes");
// Add Record to Elastic Search
var indexResponse = Client.IndexDocument(thisRecord);
}
catch (Exception excp)
{
message = "Exception: " + excp.Message;
success = false;
}
return success;
}
From within Kibana I've noticed each record has a unique _id but I can find how to retrieve that value to only update that specific document.