elastic4s icon indicating copy to clipboard operation
elastic4s copied to clipboard

Support Update By Query with slices auto

Open flavienbert opened this issue 1 year ago • 3 comments

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html#docs-update-by-query-slice According to the doc, we should be able to use the value auto with the param slices

flavienbert avatar Jun 18 '24 11:06 flavienbert

@Philippus I don't understand the error on the scala-2_12 CI. Can you help me?

flavienbert avatar Jun 18 '24 11:06 flavienbert

Actually, it partially breaks compatibility because I assume most of people use the DSL
def slices(slices: Int): UpdateByQueryRequest = copy(slices = Some(NumericSlices(slices))). We can also add an implicit conversion Int -> Slices in the scope to avoid breaking changes.

The drawback having 2 different params for the slices is that a user can use both in same time, so which one should we keep? It can be confusing.

What do you think?

flavienbert avatar Jun 19 '24 08:06 flavienbert

We can add a new parameter like numericOrAutoSlices: Option[Slices] = None and deprecate the old parameter. The new parameter should take precedence over the deprecated one. The methods then can look like this:

  def slices(slices: Int): ReindexRequest = copy(numericOrAutoSlices = NumericSlices(slices).some)
  def slicesAuto(): ReindexRequest = copy(numericOrAutoSlices = AutoSlices.some)

and in the handlers we could do something like this:

      request.numericOrAutoSlices.foreach {
        case AutoSlices            => params.put("slices", "auto")
        case NumericSlices(slices) => params.put("slices", slices.toString)
      }
      if (request.numericOrAutoSlices.isEmpty)
        request.slices.foreach(params.put("slices", _))

Philippus avatar Jul 03 '24 18:07 Philippus

I'll merge this PR, and create a follow-up to change the api a bit as I described but numericOrAutoSlices will probably become slicing to keep it a bit shorter.

Philippus avatar Aug 29 '24 21:08 Philippus