Insert and Update in less than a second. Is it safe?

Hello,
I'm completely new with elasticsearch and don't have any experience with it yet, and now I'm evaluating if it can be part of a solution I'm creating, because I would like to use kibana.

I've a JMS Queue where events are being added by other system. I'm converting these events in JSON like below:

{ "instanceId":123, "name":"TST Process", "status":"Active" }

First question. Can I update this JSON record inside elasticsearch using as filter the parameter instanceId? Something like UPDATE set status='Running' where instanceId = 123 in SQL

Second question. The update action can occur in a really small period of time (miliseconds) and I'm not sure if this kind of action is safe in elasticsearch because in the article below I read:

Elasticsearch provides data manipulation and search capabilities in near real time. By default, you can expect a one second delay (refresh interval) from the time you index/update/delete your data until the time that it appears in your search results.
https://www.elastic.co/guide/en/elasticsearch/reference/current/_modifying_your_data.html

I really appreciate any help.
Thanks

Yes, _update_by_query does this. But it is a much "heavier" thing than doing an _update using the documents ID. You should prefer the _update API if possible.

Well, with _update it is quite safe. _update performs a realtime get, which, in 5.0, if the document hasn't been refreshed already, will force a refresh of the shard to make the change visible immediately and then update. Pre 5.0 it is actually more efficient because the refresh isn't required. The change in 5.0 was to enable some other optimizations for more common use cases.

With _update_by_query you'll get a version conflict and have to manually retry.

Can I choose my own document ID, I mean, can I use instanceId value as document ID or only the system (elasticsearch) can give this auto-generated id?

You can chose your document ID. You should if you plan on updating it. Have a look at the first example here.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.