Skip to content

[series/9.x] add shard preference support for update by query async requests#3889

Open
flavienbert wants to merge 2 commits intoPhilippus:series/9.xfrom
flavienbert:ft/9.x/shards_update_by_query
Open

[series/9.x] add shard preference support for update by query async requests#3889
flavienbert wants to merge 2 commits intoPhilippus:series/9.xfrom
flavienbert:ft/9.x/shards_update_by_query

Conversation

@flavienbert
Copy link
Copy Markdown
Contributor

Add support for the preference=_shards:0,1,2,3 parameter in async update-by-query operations through a new ShardsPreferenceRequest case class.

Changes:

  • Add ShardsPreferenceRequest case class to model shard preferences. The goal of this model is to have a nonEmptyList
  • Add shards: Option[ShardsPreferenceRequest] field to UpdateByQueryAsyncRequest
  • Add fluent API methods: shards(Int) and shards(Set[Int])
  • Propagate shard preference parameter to HTTP request in UpdateByQueryHandler
  • Add comprehensive unit tests validating preference parameter building

@Philippus
Copy link
Copy Markdown
Owner

As far as I can tell, shard preference isn't the only preference option available for that call. I'd prefer to model it the same as we do with GetRequest, as in:

  def preference(pref: Preference): GetRequest = preference(pref.value)
  def preference(pref: String): GetRequest = copy(preference = pref.some)

@flavienbert flavienbert force-pushed the ft/9.x/shards_update_by_query branch from f069690 to 2f9808d Compare March 31, 2026 10:00
@flavienbert
Copy link
Copy Markdown
Contributor Author

The modification is done.
I initially overlooked the existing model, but I’m not a big fan of it:
case class Shards(ids: List[String]) extends Preference("_shards:" + ids.mkString(",")).

It doesn’t enforce that at least one shard is provided or same shards are provided, and shards are defined as String instead of Int.
My version case class ShardsPreferenceRequest(shard: Int, optionalShards: Option[Set[Int]] = None) feels safer and more type-safe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants