Updating many documents at once


(Wojciech Durczyński) #1

Hello

I'd like to modify many documents in ES at once (something similar to
sql update). To achieve this functionality now I have to get all
matching documents from ES, modify them and index again.
Is there a possibility in ES to modify many documents at once in
better and faster way?
Meybe there should be a command that takes query/filter and function
(for example in java script) that modifies source of all matching
documents.
What do you think about it? Is it possible to implement?

Regards
Wojciech Durczyński


(Karussell) #2

do you mean something like bulk updating?

http://www.elasticsearch.org/guide/reference/api/bulk.html

also possible via java api:

BulkRequestBuilder brb = client.prepareBulk();
for (Entry<String, XContentBuilder> e : docs.entrySet()) {

brb.add(Requests.indexRequest(indexName).type(indexType).id(e.getKey()).source(e.getValue()));
brb.setRefresh(true);
}
if (brb.numberOfActions() > 0)
brb.execute().actionGet();

On 8 Feb., 16:21, Wojciech Durczyński
wojciech.durczyn...@comarch.com wrote:

Hello

I'd like to modify many documents in ES at once (something similar to
sql update). To achieve this functionality now I have to get all
matching documents from ES, modify them and index again.
Is there a possibility in ES to modify many documents at once in
better and faster way?
Meybe there should be a command that takes query/filter and function
(for example in java script) that modifies source of all matching
documents.
What do you think about it? Is it possible to implement?

Regards
Wojciech Durczyński


(Enrique Medina Montenegro) #3

Scrolling can maybe also help here:

http://www.elasticsearch.org/guide/reference/api/search/scroll.html

2011/2/8 Karussell tableyourtime@googlemail.com

do you mean something like bulk updating?

http://www.elasticsearch.org/guide/reference/api/bulk.html

also possible via java api:

BulkRequestBuilder brb = client.prepareBulk();
for (Entry<String, XContentBuilder> e : docs.entrySet()) {

brb.add(Requests.indexRequest(indexName).type(indexType).id(e.getKey()).source(e.getValue()));
brb.setRefresh(true);
}
if (brb.numberOfActions() > 0)
brb.execute().actionGet();

On 8 Feb., 16:21, Wojciech Durczyński
wojciech.durczyn...@comarch.com wrote:

Hello

I'd like to modify many documents in ES at once (something similar to
sql update). To achieve this functionality now I have to get all
matching documents from ES, modify them and index again.
Is there a possibility in ES to modify many documents at once in
better and faster way?
Meybe there should be a command that takes query/filter and function
(for example in java script) that modifies source of all matching
documents.
What do you think about it? Is it possible to implement?

Regards
Wojciech Durczyński


(Shay Banon) #4

Being able to provide a query and a javascript to munge the docs is certainly something that is on the roadmap. I have talked about it with aparo and he even hacked it a bit to work on his fork.

Still, it required some foundation to be laid down in order to make it work properly. The good news is that most of the work is done with versioning. There is still some work left for replication aspect, but I certainly see such a feature in the near future.

-shay.banon
On Tuesday, February 8, 2011 at 10:53 PM, Enrique Medina Montenegro wrote:

Scrolling can maybe also help here:

http://www.elasticsearch.org/guide/reference/api/search/scroll.html

2011/2/8 Karussell tableyourtime@googlemail.com

do you mean something like bulk updating?

http://www.elasticsearch.org/guide/reference/api/bulk.html

also possible via java api:

BulkRequestBuilder brb = client.prepareBulk();
for (Entry<String, XContentBuilder> e : docs.entrySet()) {

brb.add(Requests.indexRequest(indexName).type(indexType).id(e.getKey()).source(e.getValue()));
brb.setRefresh(true);
}
if (brb.numberOfActions() > 0)
brb.execute().actionGet();

On 8 Feb., 16:21, Wojciech Durczyński
wojciech.durczyn...@comarch.com wrote:

Hello

I'd like to modify many documents in ES at once (something similar to
sql update). To achieve this functionality now I have to get all
matching documents from ES, modify them and index again.
Is there a possibility in ES to modify many documents at once in
better and faster way?
Meybe there should be a command that takes query/filter and function
(for example in java script) that modifies source of all matching
documents.
What do you think about it? Is it possible to implement?

Regards
Wojciech Durczyński


(system) #5