Reputation: 352
I recently inherited the job of maintaining our ElasticSearch indexes. So I'm still pretty new at this. I've got code in Node.js to create an index and I assume it overwrites an existing index with the same name if it already exists.
What I would like to do is insert one new record into the index leaving the existing data untouched. I've been researching how to do this here, but I'm still not clear on how to do it.
Here is code for creating an index that I'm using now, it appears that the original writer of my file got it from here:
for (let group of groups) {
await client.index({
index: "groups",
id: group.id,
body: {
name: group.name,
parent_id: group.parent_id,
level: group.level,
path: group.path,
attributes_set_id: group.attributes_set_id,
total_products: group.total_products,
active: group.active,
created_at: group.created_at,
updated_at: group.updated_at,
},
});
}
await client.indices.refresh({
index: "groups",
});
If I tried to do this with only one group
record would it replace the entire existing groups
index?
Thanks, Don
Upvotes: 1
Views: 1141
Reputation: 217284
That code doesn't create an index, but it "indexes" a document.
If a document with the same id (i.e. group.id
) already exists in the index, then it's going to be reindexed (i.e. overridden), otherwise a new document is going to be created.
So I don't think anything wrong can happen here.
Upvotes: 2