Skip to main content

Delete By Query Request

The DeleteByQuery request deletes documents that match the specified query.

To create a DeleteById request do the following:

import zio.elasticsearch.ElasticRequest.DeleteByQueryRequest
import zio.elasticsearch.ElasticRequest.deleteByQuery
// this import is required for using `IndexName`
import zio.elasticsearch._
import zio.elasticsearch.ElasticQuery._

val request: DeleteByQueryRequest = deleteByQuery(index = IndexName("index"), query = contains(field = Document.name, value = "test"))

If you want to change the refresh, you can use refresh, refreshFalse or refreshTrue method:

val requestWithRefresh: DeleteByQueryRequest = deleteByQuery(index = IndexName("index"), query = contains(field = Document.name, value = "test")).refresh(true)
val requestWithRefreshFalse: DeleteByQueryRequest = deleteByQuery(index = IndexName("index"), query = contains(field = Document.name, value = "test")).refreshFalse
val requestWithRefreshTrue: DeleteByQueryRequest = deleteByQuery(index = IndexName("index"), query = contains(field = Document.name, value = "test")).refreshTrue

If you want to change the routing, you can use the routing method:

// this import is required for `Routing` also
import zio.elasticsearch._

val requestWithRouting: DeleteByQueryRequest = deleteByQuery(index = IndexName("index"), query = contains(field = Document.name, value = "test")).routing(Routing("routing"))

You can find more information about DeleteByQuery request here.