Skip to content

Commit ba35406

Browse files
committed
Add delete-by-query plugin
The delete by query plugin adds support for deleting all of the documents (from one or more indices) which match the specified query. It is a replacement for the problematic delete-by-query functionality which has been removed from Elasticsearch core in 2.0. Internally, it uses the Scan/Scroll and Bulk APIs to delete documents in an efficient and safe manner. It is slower than the old delete-by-query functionality, but fixes the problems with the previous implementation. Closes #7052
1 parent 0434ecf commit ba35406

File tree

19 files changed

+2651
-0
lines changed

19 files changed

+2651
-0
lines changed

plugins/delete-by-query/pom.xml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Licensed to Elasticsearch under one or more contributor
3+
license agreements. See the NOTICE file distributed with this work for additional
4+
information regarding copyright ownership. ElasticSearch licenses this file to you
5+
under the Apache License, Version 2.0 (the "License"); you may not use this
6+
file except in compliance with the License. You may obtain a copy of the
7+
License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
8+
applicable law or agreed to in writing, software distributed under the License
9+
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
10+
KIND, either express or implied. See the License for the specific language
11+
governing permissions and limitations under the License. -->
12+
13+
<project xmlns="http://maven.apache.org/POM/4.0.0"
14+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
15+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
16+
<modelVersion>4.0.0</modelVersion>
17+
18+
<groupId>org.elasticsearch.plugin</groupId>
19+
<artifactId>elasticsearch-delete-by-query</artifactId>
20+
21+
<packaging>jar</packaging>
22+
<name>Elasticsearch Delete By Query plugin</name>
23+
<description>The Delete By Query plugin allows to delete documents in Elasticsearch with a single query.</description>
24+
25+
<parent>
26+
<groupId>org.elasticsearch</groupId>
27+
<artifactId>elasticsearch-plugin</artifactId>
28+
<version>2.0.0-SNAPSHOT</version>
29+
</parent>
30+
31+
<properties>
32+
<tests.ifNoTests>warn</tests.ifNoTests>
33+
<tests.rest.suite>delete_by_query</tests.rest.suite>
34+
</properties>
35+
36+
<build>
37+
<plugins>
38+
<plugin>
39+
<groupId>org.apache.maven.plugins</groupId>
40+
<artifactId>maven-assembly-plugin</artifactId>
41+
</plugin>
42+
</plugins>
43+
</build>
44+
45+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"delete_by_query": {
3+
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete-by-query.html",
4+
"methods": ["DELETE"],
5+
"url": {
6+
"path": "/{index}/_query",
7+
"paths": ["/{index}/_query", "/{index}/{type}/_query"],
8+
"parts": {
9+
"index": {
10+
"type" : "list",
11+
"required": true,
12+
"description" : "A comma-separated list of indices to restrict the operation; use `_all` to perform the operation on all indices"
13+
},
14+
"type": {
15+
"type" : "list",
16+
"description" : "A comma-separated list of types to restrict the operation"
17+
}
18+
},
19+
"params": {
20+
"analyzer": {
21+
"type" : "string",
22+
"description" : "The analyzer to use for the query string"
23+
},
24+
"default_operator": {
25+
"type" : "enum",
26+
"options" : ["AND","OR"],
27+
"default" : "OR",
28+
"description" : "The default operator for query string query (AND or OR)"
29+
},
30+
"df": {
31+
"type" : "string",
32+
"description" : "The field to use as default where no field prefix is given in the query string"
33+
},
34+
"ignore_unavailable": {
35+
"type" : "boolean",
36+
"description" : "Whether specified concrete indices should be ignored when unavailable (missing or closed)"
37+
},
38+
"allow_no_indices": {
39+
"type" : "boolean",
40+
"description" : "Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)"
41+
},
42+
"expand_wildcards": {
43+
"type" : "enum",
44+
"options" : ["open","closed","none","all"],
45+
"default" : "open",
46+
"description" : "Whether to expand wildcard expression to concrete indices that are open, closed or both."
47+
},
48+
"q": {
49+
"type" : "string",
50+
"description" : "Query in the Lucene query string syntax"
51+
},
52+
"routing": {
53+
"type" : "string",
54+
"description" : "Specific routing value"
55+
},
56+
"source": {
57+
"type" : "string",
58+
"description" : "The URL-encoded query definition (instead of using the request body)"
59+
},
60+
"timeout": {
61+
"type" : "time",
62+
"description" : "Explicit operation timeout"
63+
}
64+
}
65+
},
66+
"body": {
67+
"description" : "A query to restrict the operation specified with the Query DSL"
68+
}
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
"Basic delete_by_query":
3+
- do:
4+
index:
5+
index: test_1
6+
type: test
7+
id: 1
8+
body: { foo: bar }
9+
10+
- do:
11+
index:
12+
index: test_1
13+
type: test
14+
id: 2
15+
body: { foo: baz }
16+
17+
- do:
18+
index:
19+
index: test_1
20+
type: test
21+
id: 3
22+
body: { foo: foo }
23+
24+
- do:
25+
indices.refresh: {}
26+
27+
- do:
28+
delete_by_query:
29+
index: test_1
30+
body:
31+
query:
32+
match:
33+
foo: bar
34+
35+
- do:
36+
indices.refresh: {}
37+
38+
- do:
39+
count:
40+
index: test_1
41+
42+
- match: { count: 2 }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0"?>
2+
<!-- Licensed to ElasticSearch under one or more contributor
3+
license agreements. See the NOTICE file distributed with this work for additional
4+
information regarding copyright ownership. ElasticSearch licenses this file to you
5+
under the Apache License, Version 2.0 (the "License"); you may not use this
6+
file except in compliance with the License. You may obtain a copy of the
7+
License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
8+
applicable law or agreed to in writing, software distributed under the License
9+
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
10+
KIND, either express or implied. See the License for the specific language
11+
governing permissions and limitations under the License. -->
12+
13+
<assembly>
14+
<id>plugin</id>
15+
<formats>
16+
<format>zip</format>
17+
</formats>
18+
<includeBaseDirectory>false</includeBaseDirectory>
19+
<dependencySets>
20+
<dependencySet>
21+
<outputDirectory>/</outputDirectory>
22+
<useProjectArtifact>true</useProjectArtifact>
23+
<useTransitiveFiltering>true</useTransitiveFiltering>
24+
<excludes>
25+
<exclude>org.elasticsearch:elasticsearch</exclude>
26+
</excludes>
27+
</dependencySet>
28+
<dependencySet>
29+
<outputDirectory>/</outputDirectory>
30+
<useProjectArtifact>true</useProjectArtifact>
31+
<useTransitiveFiltering>true</useTransitiveFiltering>
32+
</dependencySet>
33+
</dependencySets>
34+
</assembly>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.action.deletebyquery;
21+
22+
import org.elasticsearch.action.Action;
23+
import org.elasticsearch.client.ElasticsearchClient;
24+
25+
public class DeleteByQueryAction extends Action<DeleteByQueryRequest, DeleteByQueryResponse, DeleteByQueryRequestBuilder> {
26+
27+
public static final DeleteByQueryAction INSTANCE = new DeleteByQueryAction();
28+
public static final String NAME = "indices:data/write/delete/by_query";
29+
30+
private DeleteByQueryAction() {
31+
super(NAME);
32+
}
33+
34+
@Override
35+
public DeleteByQueryResponse newResponse() {
36+
return new DeleteByQueryResponse();
37+
}
38+
39+
@Override
40+
public DeleteByQueryRequestBuilder newRequestBuilder(ElasticsearchClient client) {
41+
return new DeleteByQueryRequestBuilder(client, this);
42+
}
43+
}

0 commit comments

Comments
 (0)