Skip to content

Commit 4c5df16

Browse files
author
Olivier Favre
committed
1 parent f110aaa commit 4c5df16

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed

README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
ElasticSearch Update By Query Plugin
2+
====================================
3+
4+
The update by query API allows all documents that with the query to be updated with a script.
5+
This is experimental.
6+
7+
This plugin is an adaptation of elasticsearch/elasticsearch#2230.
8+
9+
Installation
10+
-----------
11+
12+
Simply run at the root of your ElasticSearch v0.20.2+ installation:
13+
14+
bin/plugin -install com.yakaz.elasticsearch.plugins/elasticsearch-action-updatebyquery/1.0.0
15+
16+
This will download the plugin from the Central Maven Repository.
17+
18+
For older versions of ElasticSearch, you can still use the longer:
19+
20+
bin/plugin -url http://oss.sonatype.org/content/repositories/releases/com/yakaz/elasticsearch/plugins/elasticsearch-action-updatebyquery/1.0.0/elasticsearch-action-updatebyquery-1.0.0.zip install elasticsearch-action-updatebyquery
21+
22+
In order to declare this plugin as a dependency, add the following to your `pom.xml`:
23+
24+
<dependency>
25+
<groupId>com.yakaz.elasticsearch.plugins</groupId>
26+
<artifactId>elasticsearch-action-updatebyquery/artifactId>
27+
<version>1.0.0</version>
28+
</dependency>
29+
30+
Version matrix:
31+
32+
----------------------------------------------------
33+
| Update By Query Action Plugin | ElasticSearch |
34+
----------------------------------------------------
35+
| master | 0.20.0 -> master |
36+
----------------------------------------------------
37+
| 1.0.0 | 0.20.0 -> master |
38+
----------------------------------------------------
39+
40+
Description
41+
-----------
42+
43+
The update by query API allows all documents that with the query to be updated with a script.
44+
This feature is experimental.
45+
46+
The update by query works a bit different than the delete by query.
47+
The update by query api translates the documents that match into bulk index / delete requests.
48+
After the bulk limit has been reached, the bulk requests created thus far will be executed.
49+
After the bulk requests have been executed the next batch of requests will be prepared and executed.
50+
This behavior continues until all documents that matched the query have been processed.
51+
The bulk size can be configured with the `action.updatebyquery.bulk_size` option in the elasticsearch configuration.
52+
For example: `action.updatebyquery.bulk_size=2500`
53+
54+
Example usage
55+
-------------
56+
57+
Index an example document:
58+
59+
curl -XPUT 'localhost:9200/twitter/tweet/1' -d '
60+
{
61+
"text" : {
62+
"message" : "you know for search"
63+
},
64+
"likes": 0
65+
}'
66+
67+
Execute the following update by query command:
68+
69+
curl -XPOST 'localhost:9200/twitter/_update_by_query' -d '
70+
{
71+
"query" : {
72+
"term" : {
73+
"message" : "you"
74+
}
75+
},
76+
"script" : "ctx._source.likes += 1"
77+
}'
78+
79+
This will yield the following response:
80+
81+
{
82+
"ok" : true,
83+
"took" : 9,
84+
"total" : 1,
85+
"updated" : 1,
86+
"indices" : [ {
87+
"twitter" : { }
88+
} ]
89+
}
90+
91+
By default no bulk item responses are included in the response.
92+
If there are bulk item responses included in the response, the bulk response items are grouped by index and shard.
93+
This can be controlled by the `response` option.
94+
95+
Options:
96+
--------
97+
98+
Additional general options in request body:
99+
100+
* `lang`: The script language.
101+
* `params`: The script parameters.
102+
103+
### Query string options:
104+
105+
* `replication`: The replication type for the delete/index operation (sync or async).
106+
* `consistency`: The write consistency of the index/delete operation.
107+
* `response`: What bulk response items to include into the update by query response.
108+
This can be set to the following: `none`, `failed` and `all`.
109+
Defaults to `none`.
110+
Warning: `all` can result in out of memory errors when the query results in many hits.
111+
* `routing`: Sets the routing that will be used to route the document to the relevant shard.
112+
* `timeout`: Timeout waiting for a shard to become available.

0 commit comments

Comments
 (0)