Elasticsearch version: 5.1.1
OS version: centos 7
Description of the problem including expected versus actual behavior:
ES 5.1 version does not support delete-by-query plugin.
so i need to change the javaAPI code.
The following code is from the previous 2.3 version.
new DeleteByQueryRequestBuilder(ElasticConnector.getInstance().getJavaClient(), DeleteByQueryAction.INSTANCE) .setIndices(GLOBAL_ID) .setTypes(MessageService.DEVICE) .setQuery(QueryBuilders.boolQuery().should(QueryBuilders.termQuery("user_id", user_id)) .should(QueryBuilders.termQuery("device_id", device_id) .mustNot(QueryBuilders.boolQuery().must(QueryBuilders.termQuery("user_id", user_id)) .must(QueryBuilders.termQuery("device_id", device_id)) )).execute().actionGet();t
indent
This code has a problem with "DeleteByQueryRequestBuilder cannot be resolved to a type"
How do I change?
nik9000
(Nik Everett)
January 4, 2017, 2:10am
2
In 5.1 delete by query was moved into the reindex module so it is shipped by default with Elasticsearch. You should be able to use it over the java API if you are using the PreBuiltTransportClient described here . This ought to work:
import org.elasticsearch.index.reindex.DeleteByQueryAction;
...
DeleteByQueryAction.newRequestBuilder(client)
1 Like
DeleteByQueryResponse rsp =
new DeleteByQueryRequestBuilder(Client, DeleteByQueryAction.INSTANCE)
.setIndices("Indice")
.setTypes("Type")
.setQuery(QueryBuilders.termQuery("rowid", rowid))
.execute()
.actionGet();
I changed it to deleteByqueryAction.
BulkIndexByScrollResponse = DeleteByQueryAction.INSTANCE.newRequestBuilder(Client)
.source("Indice")
.filter(QueryBuilders.termQuery("rowid", rowid))
.execute()
.actionGet();
.setIndices("Indice") is changed to .source("Indice"), and .setQuery() is changed to .filter()
Is that right?
And how do I change the .setType()?
dadoonet
(David Pilato)
January 9, 2017, 7:09am
4
thanks!
Is setType used only for search?
Can not use delete?
dadoonet
(David Pilato)
January 9, 2017, 7:52am
6
You can use this type query within a bool query as a filter clause.
Add your QueryBuilders.termQuery("rowid", rowid)
also as another filter clause.
Then add this bool query to .filter()
I'm curious about what you are doing though. Are you removing only one single document with the delete by query API?
Yes.
I want to delete documents that are executed by queryDSL
under specific index, type, and routing conditions.
and i add type condition, as below.
BulkIndexByScrollResponse = DeleteByQueryAction.INSTANCE.newRequestBuilder(Client)
.source("Indice")
.filter(QueryBuilders.termQuery("rowid", rowid))
.filter(QueryBuilders.typeQuery("Type")
.execute()
.actionGet();
.setRouting ("_ id") is still not resolved ...
dadoonet
(David Pilato)
January 9, 2017, 7:25pm
8
I meant using a bool query which has 2 filters.
Something like:
"bool" : {
"filter": [
{ "term" : { "rowid" : "rowid" } },
{ "type" : { "value" : "Type" } }
]
}
Then add this boolQuery with filter(boolQuery)
to your delete by query operation.
Thank you very much for your interest.
I did it the way you told me, but it does not work.
There is no filter(boolQuery), and there are no type-related functions in the BoolQueryBuilder.
dadoonet
(David Pilato)
January 10, 2017, 6:50am
10
QueryBuilders.boolQuery().filter(clause1).filter(clause2)
system
(system)
Closed
February 7, 2017, 6:50am
11
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.