Skip to content

Commit

Permalink
Allow passing "auto" as the slices parameter (#553)
Browse files Browse the repository at this point in the history
* Allow passing `"auto"` as the `slices` parameter

Signed-off-by: Thomas Farr <[email protected]>

* Update CHANGELOG

Signed-off-by: Thomas Farr <[email protected]>

* Fix license header

Signed-off-by: Thomas Farr <[email protected]>

---------

Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia authored Feb 28, 2024
1 parent 8085401 commit cd4bd52
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 134 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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 `Microsoft.CodeAnalysis.CSharp` from 4.2.0 to 4.6.0
Expand Down Expand Up @@ -151,4 +152,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
[1.6.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.5.0...v1.6.0
[1.5.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.4.0...v1.5.0
[1.4.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.3.0...v1.4.0
[1.3.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.2.0...v1.3.0
[1.3.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.2.0...v1.3.0

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 @@ -372,7 +372,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 @@ -1186,7 +1186,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 @@ -1666,7 +1666,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
};
}
31 changes: 31 additions & 0 deletions src/OpenSearch.Client/Document/Multiple/Slices/SlicesFormatter.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;

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 @@ -786,9 +786,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 @@ -2492,9 +2492,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 @@ -3620,9 +3620,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
};
}
}

0 comments on commit cd4bd52

Please sign in to comment.