update_by_query
The function update_by_query(collection_name, body) updatesl documents according to the query conditions
Input-
collection_name – Specifies the Collection with the documents to delete
body– The query that specifies the conditions for documents to be updated
Example-
hyperspace_client.delete_by_query(collection_name,
body = {"query": {
"bool": {
"must": {
"term": {
"name": "John"
},
}
},
"script": "ctx._source.name = 'Bob'",
})
String queryJson =
"{" +
" \"query\": {" +
" \"bool\": {" +
" \"must\": [" +
" {" +
" \"term\":{" +
" \"name\":\"John\"" +
" }" +
" }" +
" ]" +
" }" +
" }" +
"script: "ctx._source.name = \"Bob\"",
"}";
JsonObject query = JsonParser.parseString(queryJson).getAsJsonObject();
DeleteByQueryRequest queryRequest = new DeleteByQueryRequest();
queryRequest.setQuery(query);
DeleteByQueryResponse response = client.uodateByQuery(collectionName, queryRequest);
System.out.println(response.getTook());
System.out.println(response.getDeleted());await client.updateByQuery({
index: collectionName,
body: {
query: {
bool: {
must: [
{
term: {
name: "John"
},
}
]
}
},
script: "ctx._source.name = \"Bob\"",
}
});Last updated