Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 1.x] Allow passing "auto" as the slices parameter #561

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Fixed `HttpConnection.ConvertHttpMethod` to support `Patch` method ([#489](https://github.com/opensearch-project/opensearch-net/pull/489))
- Fixed `IEnumerable<int?>` property mapping. ([#503](https://github.com/opensearch-project/opensearch-net/pull/503))
- Fixed `ConnectionConfiguration.DefaultMemoryStreamFactory` actually used as default. ([#552](https://github.com/opensearch-project/opensearch-net/pull/552))
- Fixed passing `"auto"` to the `slices` parameter ([#553](https://github.com/opensearch-project/opensearch-net/pull/553))

### Dependencies
- Bumps `NSwag.Core.Yaml` from 13.19.0 to 14.0.3
Expand Down

This file was deleted.

This file was deleted.

6 changes: 3 additions & 3 deletions src/OpenSearch.Client/Descriptors.NoNamespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public DeleteByQueryDescriptor<TDocument> Index<TOther>()
///<summary>Search operation type</summary>
public DeleteByQueryDescriptor<TDocument> SearchType(SearchType? searchtype) => Qs("search_type", searchtype);
///<summary>The number of slices this task should be divided into. Defaults to 1, meaning the task isn't sliced into subtasks.</summary>
public DeleteByQueryDescriptor<TDocument> Slices(long? slices) => Qs("slices", slices);
public DeleteByQueryDescriptor<TDocument> Slices(Slices slices) => Qs("slices", slices);
///<summary>A comma-separated list of &lt;field&gt;:&lt;direction&gt; pairs</summary>
public DeleteByQueryDescriptor<TDocument> Sort(params string[] sort) => Qs("sort", sort);
///<summary>Whether the _source should be included in the response.</summary>
Expand Down Expand Up @@ -1171,7 +1171,7 @@ public partial class ReindexOnServerDescriptor : RequestDescriptorBase<ReindexOn
///<summary>Control how long to keep the search context alive</summary>
public ReindexOnServerDescriptor Scroll(Time scroll) => Qs("scroll", scroll);
///<summary>The number of slices this task should be divided into. Defaults to 1, meaning the task isn't sliced into subtasks. Can be set to `auto`.</summary>
public ReindexOnServerDescriptor Slices(long? slices) => Qs("slices", slices);
public ReindexOnServerDescriptor Slices(Slices slices) => Qs("slices", slices);
///<summary>Time each individual bulk request should wait for shards that are unavailable.</summary>
public ReindexOnServerDescriptor Timeout(Time timeout) => Qs("timeout", timeout);
///<summary>Sets the number of shard copies that must be active before proceeding with the reindex operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)</summary>
Expand Down Expand Up @@ -1651,7 +1651,7 @@ public UpdateByQueryDescriptor<TDocument> Index<TOther>()
///<summary>Search operation type</summary>
public UpdateByQueryDescriptor<TDocument> SearchType(SearchType? searchtype) => Qs("search_type", searchtype);
///<summary>The number of slices this task should be divided into. Defaults to 1, meaning the task isn't sliced into subtasks. Can be set to `auto`.</summary>
public UpdateByQueryDescriptor<TDocument> Slices(long? slices) => Qs("slices", slices);
public UpdateByQueryDescriptor<TDocument> Slices(Slices slices) => Qs("slices", slices);
///<summary>A comma-separated list of &lt;field&gt;:&lt;direction&gt; pairs</summary>
public UpdateByQueryDescriptor<TDocument> Sort(params string[] sort) => Qs("sort", sort);
///<summary>Whether the _source should be included in the response.</summary>
Expand Down
29 changes: 29 additions & 0 deletions src/OpenSearch.Client/Document/Multiple/Slices/Slices.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

using OpenSearch.Net.Utf8Json;

namespace OpenSearch.Client;

[JsonFormatter(typeof(SlicesFormatter))]
public class Slices : Union<long, string>
{
public Slices(long value) : base(value) { }

public Slices(string value) : base(value) { }

public static implicit operator Slices(long value) => new(value);
public static implicit operator Slices(long? value) => value is { } v ? new Slices(v) : null;
public static implicit operator Slices(string value) => value is { } v ? new Slices(value) : null;

public override string ToString() => Tag switch
{
0 => Item1.ToString(),
1 => Item2,
_ => null
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

using OpenSearch.Net.Utf8Json;

namespace OpenSearch.Client;

internal class SlicesFormatter : IJsonFormatter<Slices>
{
private static readonly UnionFormatter<long, string> UnionFormatter = new();

public void Serialize(ref JsonWriter writer, Slices value, IJsonFormatterResolver formatterResolver) =>
UnionFormatter.Serialize(ref writer, value, formatterResolver);

public Slices Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
{
var union = UnionFormatter.Deserialize(ref reader, formatterResolver);
if (union == null) return null;

return union.Tag switch
{
0 => new Slices(union.Item1),
1 => new Slices(union.Item2),
_ => null
};
}
}
12 changes: 6 additions & 6 deletions src/OpenSearch.Client/Requests.NoNamespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -771,9 +771,9 @@ public SearchType? SearchType
}

///<summary>The number of slices this task should be divided into. Defaults to 1, meaning the task isn't sliced into subtasks.</summary>
public long? Slices
public Slices Slices
{
get => Q<long? >("slices");
get => Q<Slices>("slices");
set => Q("slices", value);
}

Expand Down Expand Up @@ -2477,9 +2477,9 @@ public Time Scroll
}

///<summary>The number of slices this task should be divided into. Defaults to 1, meaning the task isn't sliced into subtasks. Can be set to `auto`.</summary>
public long? Slices
public Slices Slices
{
get => Q<long? >("slices");
get => Q<Slices>("slices");
set => Q("slices", value);
}

Expand Down Expand Up @@ -3605,9 +3605,9 @@ public SearchType? SearchType
}

///<summary>The number of slices this task should be divided into. Defaults to 1, meaning the task isn't sliced into subtasks. Can be set to `auto`.</summary>
public long? Slices
public Slices Slices
{
get => Q<long? >("slices");
get => Q<Slices>("slices");
set => Q("slices", value);
}

Expand Down
31 changes: 31 additions & 0 deletions src/OpenSearch.Client/Search/TrackTotalHits/TrackTotalHits.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

using OpenSearch.Net.Utf8Json;

namespace OpenSearch.Client;

[JsonFormatter(typeof(TrackTotalHitsFormatter))]
public class TrackTotalHits : Union<bool, long>
{
public TrackTotalHits(bool item) : base(item) { }

public TrackTotalHits(long item) : base(item) { }

public static implicit operator TrackTotalHits(bool trackTotalHits) => new(trackTotalHits);
public static implicit operator TrackTotalHits(bool? trackTotalHits) => trackTotalHits is {} b ? new TrackTotalHits(b) : null;

public static implicit operator TrackTotalHits(long trackTotalHitsUpTo) => new(trackTotalHitsUpTo);
public static implicit operator TrackTotalHits(long? trackTotalHitsUpTo) => trackTotalHitsUpTo is {} l ? new TrackTotalHits(l) : null;

public override string ToString() => Tag switch
{
0 => Item1.ToString(),
1 => Item2.ToString(),
_ => null
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

using OpenSearch.Net.Utf8Json;

namespace OpenSearch.Client;

internal class TrackTotalHitsFormatter : IJsonFormatter<TrackTotalHits>
{
private static readonly UnionFormatter<bool, long> UnionFormatter = new();

public void Serialize(ref JsonWriter writer, TrackTotalHits value, IJsonFormatterResolver formatterResolver) =>
UnionFormatter.Serialize(ref writer, value, formatterResolver);

public TrackTotalHits Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
{
var union = UnionFormatter.Deserialize(ref reader, formatterResolver);
if (union == null) return null;
return union.Tag switch
{
0 => new TrackTotalHits(union.Item1),
1 => new TrackTotalHits(union.Item2),
_ => null
};
}
}
Loading