Retrieve records and update a field at the same time

Is there anyway when making a query in Elasticsearch, to update a field (such as say a counter++) in each record that is selected by the query.
Thanks

You can use the update by query API together with a script, but be aware this can lead to conflict if you perform concurrent updates. Elasticsearch is IMHO not really optimised for a high update rate, so if you will be having lots of concurrent updates going on I would probably reconsider the design.

Hi
Thanks for your response.
How would we reconsider the design in order to achieve this?

We could store the query and re-execute the query with the update api.

Imagine there are 1000000 queries . We would have to do another 1000000 queries just to update the field. That is exactly what we are trying to avoid.
Regards

I do not understand. What is the use case? What exactly are you trying to achieve? How frequently will you perform updates?

The frequency is about 1000 times a day (for us in any case).
The use case is the following:
Users on our site mkae a query to search for an item. These searches happen frequently, think about Etsy or Amazon people trying to find items.

For every search that is executed, a number of items will match that query which are returned to the user.

Now, what we need to do is every item that has satisfied the query and is returned, we would like to update a flag on that item showing how many times that item has satisfied the all users searches. i.e it has been included in the search results.

You would need to perform that update through a bulk update from your application tier.

Thanks.
Any examples anywhere.
Would greatly appreciate it.

I am not aware of any examples, so this is something you will need to build yourself using the language client of your choice.

It does not seem taht Elastic has a Bulk Update API - only Indexing and Deleting.
Oh well, back to square one.
Thanks anyway.

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