From 1fce876c71b9ced8e9cf902de0456f8bccc88ad4 Mon Sep 17 00:00:00 2001 From: Thomas Farr Date: Mon, 13 Nov 2023 20:27:53 +1300 Subject: [PATCH] [Backport 1.x] Add support for Point In Time APIs (#405) (#422) * Add `CreatePit` & `DeletePit` methods Signed-off-by: Thomas Farr * Add `DeleteAllPits` and `GetAllPits` methods Signed-off-by: Thomas Farr * Add PIT search support Signed-off-by: Thomas Farr * Add integration tests Signed-off-by: Thomas Farr * Add docs Signed-off-by: Thomas Farr * Add changelog entry Signed-off-by: Thomas Farr * Correct Signed-off-by: Thomas Farr * Fix changelog typo Signed-off-by: Thomas Farr * Add tests for CreatePit Signed-off-by: Thomas Farr * Add tests for DeletePit Signed-off-by: Thomas Farr * Fixing tests Signed-off-by: Thomas Farr * Cleanup Signed-off-by: Thomas Farr * Add tests for GetAllPits & DeleteAllPits Signed-off-by: Thomas Farr * PitSearch tests Signed-off-by: Thomas Farr * call isolated Signed-off-by: Thomas Farr * writable cluster Signed-off-by: Thomas Farr --------- Signed-off-by: Thomas Farr (cherry picked from commit 51114271dae2a9fa17f5339c4f36e8637d98a9cb) --- CHANGELOG.md | 5 +- guides/search.md | 181 +++++++++++++ .../Composite/CompositeAggregationSource.cs | 1 + .../Cat/CatHelpResponseBuilder.cs | 1 + .../Extensions/Extensions.cs | 7 - .../CommonOptions/Sorting/SortFormatter.cs | 1 + .../GetFieldMapping/FieldMappingFormatter.cs | 1 + .../GetRepositoryResponseFormatter.cs | 1 + .../OpenSearch.Client.csproj | 1 + .../Functions/ScoreFunctionJsonFormatter.cs | 1 + .../Geo/BoundingBox/GeoBoundingBoxQuery.cs | 1 + .../QueryDsl/Geo/Distance/GeoDistanceQuery.cs | 1 + .../QueryDsl/Geo/Polygon/GeoPolygonQuery.cs | 1 + .../Geo/Shape/GeoShapeQueryFormatter.cs | 1 + .../Specialized/Shape/CartesianPoint.cs | 1 + .../Specialized/Shape/ShapeQueryFormatter.cs | 1 + .../TermLevel/Terms/TermsQueryFormatter.cs | 1 + .../Search/PointInTime/CreatePitRequest.cs | 16 ++ .../Search/PointInTime/CreatePitResponse.cs | 23 ++ .../PointInTime/DeleteAllPitsRequest.cs | 16 ++ .../PointInTime/DeleteAllPitsResponse.cs | 18 ++ .../Search/PointInTime/DeletePitRequest.cs | 40 +++ .../Search/PointInTime/DeletePitResponse.cs | 29 ++ .../Search/PointInTime/GetAllPitsRequest.cs | 16 ++ .../Search/PointInTime/GetAllPitsResponse.cs | 31 +++ .../Search/Search/PointInTime/PointInTime.cs | 36 +++ .../Search/Search/SearchRequest.cs | 32 ++- .../_Generated/ApiUrlsLookup.cs | 60 +++++ .../_Generated/ApiUrlsLookup.generated.cs | 2 +- .../_Generated/Descriptors.NoNamespace.cs | 154 +++++++++++ .../_Generated/IOpenSearchClient.cs | 219 ++++++++++++++++ .../_Generated/OpenSearchClient.cs | 247 ++++++++++++++++++ .../_Generated/Requests.NoNamespace.cs | 177 +++++++++++++ .../Extensions/UtilExtensions.cs | 4 +- .../RequestParameters.NoNamespace.cs | 119 +++++++++ .../_Generated/IOpenSearchLowLevelClient.cs | 133 ++++++++++ .../_Generated/OpenSearchLowLevelClient.cs | 194 ++++++++++++++ tests/Tests.YamlRunner/SkipList.fs | 2 +- .../Search/PointInTime/CreatePitApiTests.cs | 76 ++++++ .../Search/PointInTime/CreatePitUrlTests.cs | 30 +++ .../PointInTime/DeleteAllPitsApiTests.cs | 81 ++++++ .../PointInTime/DeleteAllPitsUrlTests.cs | 24 ++ .../Search/PointInTime/DeletePitApiTests.cs | 83 ++++++ .../Search/PointInTime/DeletePitUrlTests.cs | 28 ++ .../Search/PointInTime/GetAllPitsApiTests.cs | 85 ++++++ .../Search/PointInTime/GetAllPitsUrlTests.cs | 24 ++ .../Search/PointInTime/PitSearchApiTests.cs | 126 +++++++++ tests/Tests/Tests.csproj | 1 - 48 files changed, 2312 insertions(+), 21 deletions(-) create mode 100644 guides/search.md create mode 100644 src/OpenSearch.Client/Search/PointInTime/CreatePitRequest.cs create mode 100644 src/OpenSearch.Client/Search/PointInTime/CreatePitResponse.cs create mode 100644 src/OpenSearch.Client/Search/PointInTime/DeleteAllPitsRequest.cs create mode 100644 src/OpenSearch.Client/Search/PointInTime/DeleteAllPitsResponse.cs create mode 100644 src/OpenSearch.Client/Search/PointInTime/DeletePitRequest.cs create mode 100644 src/OpenSearch.Client/Search/PointInTime/DeletePitResponse.cs create mode 100644 src/OpenSearch.Client/Search/PointInTime/GetAllPitsRequest.cs create mode 100644 src/OpenSearch.Client/Search/PointInTime/GetAllPitsResponse.cs create mode 100644 src/OpenSearch.Client/Search/Search/PointInTime/PointInTime.cs create mode 100644 src/OpenSearch.Client/_Generated/ApiUrlsLookup.cs create mode 100644 src/OpenSearch.Client/_Generated/Descriptors.NoNamespace.cs create mode 100644 src/OpenSearch.Client/_Generated/IOpenSearchClient.cs create mode 100644 src/OpenSearch.Client/_Generated/OpenSearchClient.cs create mode 100644 src/OpenSearch.Client/_Generated/Requests.NoNamespace.cs create mode 100644 src/OpenSearch.Net/_Generated/Api/RequestParameters/RequestParameters.NoNamespace.cs create mode 100644 src/OpenSearch.Net/_Generated/IOpenSearchLowLevelClient.cs create mode 100644 src/OpenSearch.Net/_Generated/OpenSearchLowLevelClient.cs create mode 100644 tests/Tests/Search/PointInTime/CreatePitApiTests.cs create mode 100644 tests/Tests/Search/PointInTime/CreatePitUrlTests.cs create mode 100644 tests/Tests/Search/PointInTime/DeleteAllPitsApiTests.cs create mode 100644 tests/Tests/Search/PointInTime/DeleteAllPitsUrlTests.cs create mode 100644 tests/Tests/Search/PointInTime/DeletePitApiTests.cs create mode 100644 tests/Tests/Search/PointInTime/DeletePitUrlTests.cs create mode 100644 tests/Tests/Search/PointInTime/GetAllPitsApiTests.cs create mode 100644 tests/Tests/Search/PointInTime/GetAllPitsUrlTests.cs create mode 100644 tests/Tests/Search/PointInTime/PitSearchApiTests.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index f181c786c4..bc9344190f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] +### Added +- Added support for point-in-time search and associated APIs ([#405](https://github.com/opensearch-project/opensearch-net/pull/405)) + ### Dependencies - Bumps `FSharp.Data` from 6.2.0 to 6.3.0 - Bumps `BenchMarkDotNet` from 0.13.7 to 0.13.10 @@ -98,4 +101,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) [Unreleased]: https://github.com/opensearch-project/opensearch-net/compare/v1.5.0...1.x [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 \ No newline at end of file +[1.3.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.2.0...v1.3.0 diff --git a/guides/search.md b/guides/search.md new file mode 100644 index 0000000000..ed8d022a97 --- /dev/null +++ b/guides/search.md @@ -0,0 +1,181 @@ +# Search +OpenSearch provides a powerful search API that allows you to search for documents in an index. The search API supports a number of parameters that allow you to customize the search operation. In this guide, we will explore the search API and its parameters. + +## Setup +Let's start by creating an index and adding some documents to it: + +```csharp +using OpenSearch.Client; +using OpenSearch.Net; + +var node = new Uri("https://localhost:9200"); +var config = new ConnectionSettings(node) + .ThrowExceptions() + .ServerCertificateValidationCallback(CertificateValidations.AllowAll) + .BasicAuthentication("admin", "admin"); +var client = new OpenSearchClient(config); + +class Movie +{ + public string Title { get; set; } + public string Director { get; set; } + public int Year { get; set; } + public override string ToString() + { + return $"{nameof(Title)}: {Title}, {nameof(Director)}: {Director}, {nameof(Year)}: {Year}"; + } +} + +await client.Indices.CreateAsync("movies", c => c + .Settings(s => s + .NumberOfShards(1) + .NumberOfReplicas(0) + ) + .Map(m => m + .Properties(p => p + .Text(t => t + .Name(o => o.Title)) + .Text(t => t + .Name(o => o.Director)) + .Number(n => n + .Name(o => o.Year) + .Type(NumberType.Integer))))); + +var movies = new List +{ + new Movie { Title = "The Godfather", Director = "Francis Ford Coppola", Year = 1972 }, + new Movie { Title = "The Shawshank Redemption", Director = "Frank Darabont", Year = 1994 }, +}; + +for (var i = 0; i < 10; ++i) + movies.Add(new Movie { Title = "The Dark Knight " + i, Director = "Christopher Nolan", Year = 2008 + i }); + +// Index the movies +var indexResponse = await client.BulkAsync(b => b + .Index("movies") + .IndexMany(movies) + .Refresh(Refresh.WaitFor)); +Console.WriteLine($"Indexed {indexResponse.Items.Count} movies"); // Indexed 12 movies +``` + + +## Search API + +### Basic Search +The search API allows you to search for documents in an index. The following example searches for ALL documents in the `movies` index: + +```csharp +var searchResponse = await client.SearchAsync(s => s + .Index("movies") + .Query(q => q.MatchAll())); +Console.WriteLine(string.Join('\n', searchResponse.Documents)); +``` + +You can also search for documents that match a specific query. The following example searches for documents that match the query `dark knight`: +```csharp +var searchResponse = await client.SearchAsync(s => s + .Index("movies") + .Query(q => q + .Match(m => m + .Field(f => f.Title) + .Query("dark knight")))); +Console.WriteLine(string.Join('\n', searchResponse.Documents)); +``` + +OpenSearch query DSL allows you to specify complex queries. Check out the [OpenSearch query DSL documentation](https://opensearch.org/docs/latest/query-dsl/) for more information. + + +### Basic Pagination +The search API allows you to paginate through the search results. The following example searches for documents that match the query `dark knight`, sorted by `year` in in ascending order, and returns the first 2 results after skipping the first 5 results: + +```csharp +var query = Query.Match(m => m + .Field(f => f.Title) + .Query("dark knight")); +var sort = new SortDescriptor() + .Ascending(f => f.Year); +var searchResponse = await client.SearchAsync(s => s + .Index("movies") + .Query(_ => query) + .Sort(_ => sort) + .From(5) + .Size(2)); +Console.WriteLine(string.Join('\n', searchResponse.Documents)); +``` + +With sorting, you can also use the `SearchAfter` parameter to paginate through the search results. Let's say you have already displayed the first page of results, and you want to display the next page. You can use the `SearchAfter` parameter to paginate through the search results. The following example will demonstrate how to get the first 3 pages of results using the search query of the previous example: + +```csharp +var page1 = await client.SearchAsync(s => s + .Index("movies") + .Query(_ => query) + .Sort(_ => sort) + .Size(2)); +var page2 = await client.SearchAsync(s => s + .Index("movies") + .Query(_ => query) + .Sort(_ => sort) + .Size(2) + .SearchAfter(page1.Hits.Last().Sorts)); +var page3 = await client.SearchAsync(s => s + .Index("movies") + .Query(_ => query) + .Sort(_ => sort) + .Size(2) + .SearchAfter(page2.Hits.Last().Sorts)); +Console.WriteLine(string.Join('\n', page3.Documents)); +``` + +### Pagination with Scroll API +When retrieving large amounts of non-real-time data, you can use the `scroll` parameter to paginate through the search results: + +```csharp +var page1 = await client.SearchAsync(s => s + .Index("movies") + .Query(_ => query) + .Sort(_ => sort) + .Size(2) + .Scroll("1m")); +var page2 = await client.ScrollAsync("1m", page1.ScrollId); +var page3 = await client.ScrollAsync("1m", page2.ScrollId); +Console.WriteLine(string.Join('\n', page3.Documents)); +``` + +### Pagination with Point in Time +The scroll example above has one weakness: if the index is updated while you are scrolling through the results, they will be paginated inconsistently. To avoid this, you should use the "Point in Time" feature. The following example demonstrates how to use the `point_in_time` and `pit_id` parameters to paginate through the search results: + +```csharp +var pitResp = await client.CreatePitAsync("movies", p => p.KeepAlive("1m")); + +var page1 = await client.SearchAsync(s => s + .Query(_ => query) + .Sort(_ => sort) + .Size(2) + .PointInTime(p => p.Id(pitResp.PitId).KeepAlive("1m"))); +var page2 = await client.SearchAsync(s => s + .Query(_ => query) + .Sort(_ => sort) + .Size(2) + .PointInTime(p => p.Id(pitResp.PitId).KeepAlive("1m")) + .SearchAfter(page1.Hits.Last().Sorts)); +var page3 = await client.SearchAsync(s => s + .Query(_ => query) + .Sort(_ => sort) + .Size(2) + .PointInTime(p => p.Id(pitResp.PitId).KeepAlive("1m")) + .SearchAfter(page2.Hits.Last().Sorts)); + +foreach (var doc in page1.Documents.Concat(page2.Documents).Concat(page3.Documents)) +{ + Console.WriteLine(doc.Title); +} + +await client.DeletePitAsync(p => p.PitId(pitResp.PitId)); +``` + +Note that a point-in-time is associated with an index or a set of index. So, when performing a search with a point-in-time, you DO NOT specify the index in the search. + +## Cleanup +```csharp +await client.Indices.DeleteAsync("movies"); +``` diff --git a/src/OpenSearch.Client/Aggregations/Bucket/Composite/CompositeAggregationSource.cs b/src/OpenSearch.Client/Aggregations/Bucket/Composite/CompositeAggregationSource.cs index fbc79be0f8..db86b3b970 100644 --- a/src/OpenSearch.Client/Aggregations/Bucket/Composite/CompositeAggregationSource.cs +++ b/src/OpenSearch.Client/Aggregations/Bucket/Composite/CompositeAggregationSource.cs @@ -30,6 +30,7 @@ using System.Collections.Generic; using System.Linq.Expressions; using System.Runtime.Serialization; +using OpenSearch.Net.Extensions; using OpenSearch.Net.Utf8Json; using OpenSearch.Net.Utf8Json.Internal; using OpenSearch.Net.Utf8Json.Resolvers; diff --git a/src/OpenSearch.Client/Cat/CatHelpResponseBuilder.cs b/src/OpenSearch.Client/Cat/CatHelpResponseBuilder.cs index 13bb022ec3..21cbf82a92 100644 --- a/src/OpenSearch.Client/Cat/CatHelpResponseBuilder.cs +++ b/src/OpenSearch.Client/Cat/CatHelpResponseBuilder.cs @@ -31,6 +31,7 @@ using System.Threading; using System.Threading.Tasks; using OpenSearch.Net; +using OpenSearch.Net.Extensions; namespace OpenSearch.Client { diff --git a/src/OpenSearch.Client/CommonAbstractions/Extensions/Extensions.cs b/src/OpenSearch.Client/CommonAbstractions/Extensions/Extensions.cs index 2e9e7bebde..932b481de5 100644 --- a/src/OpenSearch.Client/CommonAbstractions/Extensions/Extensions.cs +++ b/src/OpenSearch.Client/CommonAbstractions/Extensions/Extensions.cs @@ -114,13 +114,6 @@ internal static string ToEnumValue(this T enumValue) where T : struct return null; } - internal static string Utf8String(this ref ArraySegment segment) => - StringEncoding.UTF8.GetString(segment.Array, segment.Offset, segment.Count); - - internal static string Utf8String(this byte[] bytes) => bytes == null ? null : Encoding.UTF8.GetString(bytes, 0, bytes.Length); - - internal static byte[] Utf8Bytes(this string s) => s.IsNullOrEmpty() ? null : Encoding.UTF8.GetBytes(s); - internal static bool IsNullOrEmpty(this IndexName value) => value == null || value.GetHashCode() == 0; internal static bool IsNullable(this Type type) => diff --git a/src/OpenSearch.Client/CommonOptions/Sorting/SortFormatter.cs b/src/OpenSearch.Client/CommonOptions/Sorting/SortFormatter.cs index 196016fd70..14118e00e5 100644 --- a/src/OpenSearch.Client/CommonOptions/Sorting/SortFormatter.cs +++ b/src/OpenSearch.Client/CommonOptions/Sorting/SortFormatter.cs @@ -27,6 +27,7 @@ */ using System.Collections.Generic; +using OpenSearch.Net.Extensions; using OpenSearch.Net.Utf8Json; using OpenSearch.Net.Utf8Json.Internal; using OpenSearch.Net.Utf8Json.Resolvers; diff --git a/src/OpenSearch.Client/Indices/MappingManagement/GetFieldMapping/FieldMappingFormatter.cs b/src/OpenSearch.Client/Indices/MappingManagement/GetFieldMapping/FieldMappingFormatter.cs index b617fb746a..a974a6a63b 100644 --- a/src/OpenSearch.Client/Indices/MappingManagement/GetFieldMapping/FieldMappingFormatter.cs +++ b/src/OpenSearch.Client/Indices/MappingManagement/GetFieldMapping/FieldMappingFormatter.cs @@ -27,6 +27,7 @@ */ using System.Collections.Generic; +using OpenSearch.Net.Extensions; using OpenSearch.Net.Utf8Json; using OpenSearch.Net.Utf8Json.Internal; using OpenSearch.Net.Utf8Json.Resolvers; diff --git a/src/OpenSearch.Client/Modules/SnapshotAndRestore/Repositories/GetRepository/GetRepositoryResponseFormatter.cs b/src/OpenSearch.Client/Modules/SnapshotAndRestore/Repositories/GetRepository/GetRepositoryResponseFormatter.cs index 9c54730985..d7ab788342 100644 --- a/src/OpenSearch.Client/Modules/SnapshotAndRestore/Repositories/GetRepository/GetRepositoryResponseFormatter.cs +++ b/src/OpenSearch.Client/Modules/SnapshotAndRestore/Repositories/GetRepository/GetRepositoryResponseFormatter.cs @@ -29,6 +29,7 @@ using System; using System.Collections.Generic; using OpenSearch.Net; +using OpenSearch.Net.Extensions; using OpenSearch.Net.Utf8Json; using OpenSearch.Net.Utf8Json.Resolvers; diff --git a/src/OpenSearch.Client/OpenSearch.Client.csproj b/src/OpenSearch.Client/OpenSearch.Client.csproj index 19f80f288f..c2915542aa 100644 --- a/src/OpenSearch.Client/OpenSearch.Client.csproj +++ b/src/OpenSearch.Client/OpenSearch.Client.csproj @@ -19,6 +19,7 @@ + diff --git a/src/OpenSearch.Client/QueryDsl/Compound/FunctionScore/Functions/ScoreFunctionJsonFormatter.cs b/src/OpenSearch.Client/QueryDsl/Compound/FunctionScore/Functions/ScoreFunctionJsonFormatter.cs index 574d9fbc50..da73d16ca4 100644 --- a/src/OpenSearch.Client/QueryDsl/Compound/FunctionScore/Functions/ScoreFunctionJsonFormatter.cs +++ b/src/OpenSearch.Client/QueryDsl/Compound/FunctionScore/Functions/ScoreFunctionJsonFormatter.cs @@ -28,6 +28,7 @@ using System; using OpenSearch.Net; +using OpenSearch.Net.Extensions; using OpenSearch.Net.Utf8Json; using OpenSearch.Net.Utf8Json.Internal; diff --git a/src/OpenSearch.Client/QueryDsl/Geo/BoundingBox/GeoBoundingBoxQuery.cs b/src/OpenSearch.Client/QueryDsl/Geo/BoundingBox/GeoBoundingBoxQuery.cs index 0a163437c2..18247687e9 100644 --- a/src/OpenSearch.Client/QueryDsl/Geo/BoundingBox/GeoBoundingBoxQuery.cs +++ b/src/OpenSearch.Client/QueryDsl/Geo/BoundingBox/GeoBoundingBoxQuery.cs @@ -27,6 +27,7 @@ */ using System; +using OpenSearch.Net.Extensions; using OpenSearch.Net.Utf8Json; using OpenSearch.Net.Utf8Json.Internal; diff --git a/src/OpenSearch.Client/QueryDsl/Geo/Distance/GeoDistanceQuery.cs b/src/OpenSearch.Client/QueryDsl/Geo/Distance/GeoDistanceQuery.cs index ff41ecaff5..a68e386966 100644 --- a/src/OpenSearch.Client/QueryDsl/Geo/Distance/GeoDistanceQuery.cs +++ b/src/OpenSearch.Client/QueryDsl/Geo/Distance/GeoDistanceQuery.cs @@ -26,6 +26,7 @@ * under the License. */ +using OpenSearch.Net.Extensions; using OpenSearch.Net.Utf8Json; using OpenSearch.Net.Utf8Json.Internal; diff --git a/src/OpenSearch.Client/QueryDsl/Geo/Polygon/GeoPolygonQuery.cs b/src/OpenSearch.Client/QueryDsl/Geo/Polygon/GeoPolygonQuery.cs index 6aa633ce07..24f0c96b0c 100644 --- a/src/OpenSearch.Client/QueryDsl/Geo/Polygon/GeoPolygonQuery.cs +++ b/src/OpenSearch.Client/QueryDsl/Geo/Polygon/GeoPolygonQuery.cs @@ -27,6 +27,7 @@ */ using System.Collections.Generic; +using OpenSearch.Net.Extensions; using OpenSearch.Net.Utf8Json; using OpenSearch.Net.Utf8Json.Internal; diff --git a/src/OpenSearch.Client/QueryDsl/Geo/Shape/GeoShapeQueryFormatter.cs b/src/OpenSearch.Client/QueryDsl/Geo/Shape/GeoShapeQueryFormatter.cs index 78530db7d7..b1d210c3d1 100644 --- a/src/OpenSearch.Client/QueryDsl/Geo/Shape/GeoShapeQueryFormatter.cs +++ b/src/OpenSearch.Client/QueryDsl/Geo/Shape/GeoShapeQueryFormatter.cs @@ -27,6 +27,7 @@ */ using System; +using OpenSearch.Net.Extensions; using OpenSearch.Net.Utf8Json; using OpenSearch.Net.Utf8Json.Internal; diff --git a/src/OpenSearch.Client/QueryDsl/Specialized/Shape/CartesianPoint.cs b/src/OpenSearch.Client/QueryDsl/Specialized/Shape/CartesianPoint.cs index 763c77c11f..0001b8bc0a 100644 --- a/src/OpenSearch.Client/QueryDsl/Specialized/Shape/CartesianPoint.cs +++ b/src/OpenSearch.Client/QueryDsl/Specialized/Shape/CartesianPoint.cs @@ -32,6 +32,7 @@ using OpenSearch.Net.Utf8Json; using OpenSearch.Net.Utf8Json.Internal; using OpenSearch.Client; +using OpenSearch.Net.Extensions; namespace OpenSearch.Client { diff --git a/src/OpenSearch.Client/QueryDsl/Specialized/Shape/ShapeQueryFormatter.cs b/src/OpenSearch.Client/QueryDsl/Specialized/Shape/ShapeQueryFormatter.cs index 90c2ffdc73..0660c89fd7 100644 --- a/src/OpenSearch.Client/QueryDsl/Specialized/Shape/ShapeQueryFormatter.cs +++ b/src/OpenSearch.Client/QueryDsl/Specialized/Shape/ShapeQueryFormatter.cs @@ -27,6 +27,7 @@ */ using System; +using OpenSearch.Net.Extensions; using OpenSearch.Net.Utf8Json; using OpenSearch.Net.Utf8Json.Internal; diff --git a/src/OpenSearch.Client/QueryDsl/TermLevel/Terms/TermsQueryFormatter.cs b/src/OpenSearch.Client/QueryDsl/TermLevel/Terms/TermsQueryFormatter.cs index d4c177aa20..b4d12d8ffb 100644 --- a/src/OpenSearch.Client/QueryDsl/TermLevel/Terms/TermsQueryFormatter.cs +++ b/src/OpenSearch.Client/QueryDsl/TermLevel/Terms/TermsQueryFormatter.cs @@ -27,6 +27,7 @@ */ using System.Collections.Generic; +using OpenSearch.Net.Extensions; using OpenSearch.Net.Utf8Json; using OpenSearch.Net.Utf8Json.Internal; diff --git a/src/OpenSearch.Client/Search/PointInTime/CreatePitRequest.cs b/src/OpenSearch.Client/Search/PointInTime/CreatePitRequest.cs new file mode 100644 index 0000000000..7db0af0408 --- /dev/null +++ b/src/OpenSearch.Client/Search/PointInTime/CreatePitRequest.cs @@ -0,0 +1,16 @@ +/* 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. +*/ + +namespace OpenSearch.Client; + +[MapsApi("create_pit")] +[ReadAs(typeof(CreatePitRequest))] +public partial interface ICreatePitRequest { } + +public partial class CreatePitRequest { } + +public partial class CreatePitDescriptor { } diff --git a/src/OpenSearch.Client/Search/PointInTime/CreatePitResponse.cs b/src/OpenSearch.Client/Search/PointInTime/CreatePitResponse.cs new file mode 100644 index 0000000000..13d1fe8660 --- /dev/null +++ b/src/OpenSearch.Client/Search/PointInTime/CreatePitResponse.cs @@ -0,0 +1,23 @@ +/* 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 System.Runtime.Serialization; + +namespace OpenSearch.Client; + +[DataContract] +public class CreatePitResponse : ResponseBase +{ + [DataMember(Name = "pit_id")] + public string PitId { get; internal set; } + + [DataMember(Name = "_shards")] + public ShardStatistics Shards { get; internal set; } + + [DataMember(Name = "creation_time")] + public long CreationTime { get; internal set; } +} diff --git a/src/OpenSearch.Client/Search/PointInTime/DeleteAllPitsRequest.cs b/src/OpenSearch.Client/Search/PointInTime/DeleteAllPitsRequest.cs new file mode 100644 index 0000000000..a45efd2716 --- /dev/null +++ b/src/OpenSearch.Client/Search/PointInTime/DeleteAllPitsRequest.cs @@ -0,0 +1,16 @@ +/* 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. +*/ + +namespace OpenSearch.Client; + +[MapsApi("delete_all_pits")] +[ReadAs(typeof(DeleteAllPitsRequest))] +public partial interface IDeleteAllPitsRequest { } + +public partial class DeleteAllPitsRequest { } + +public partial class DeleteAllPitsDescriptor { } diff --git a/src/OpenSearch.Client/Search/PointInTime/DeleteAllPitsResponse.cs b/src/OpenSearch.Client/Search/PointInTime/DeleteAllPitsResponse.cs new file mode 100644 index 0000000000..fa86aeedb2 --- /dev/null +++ b/src/OpenSearch.Client/Search/PointInTime/DeleteAllPitsResponse.cs @@ -0,0 +1,18 @@ +/* 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 System.Collections.Generic; +using System.Runtime.Serialization; + +namespace OpenSearch.Client; + +[DataContract] +public class DeleteAllPitsResponse : ResponseBase +{ + [DataMember(Name = "pits")] + public IReadOnlyCollection Pits { get; internal set; } +} diff --git a/src/OpenSearch.Client/Search/PointInTime/DeletePitRequest.cs b/src/OpenSearch.Client/Search/PointInTime/DeletePitRequest.cs new file mode 100644 index 0000000000..456d18a6e8 --- /dev/null +++ b/src/OpenSearch.Client/Search/PointInTime/DeletePitRequest.cs @@ -0,0 +1,40 @@ +/* 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 System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; + +namespace OpenSearch.Client; + +[MapsApi("delete_pit")] +[ReadAs(typeof(DeletePitRequest))] +public partial interface IDeletePitRequest +{ + [DataMember(Name = "pit_id")] + IEnumerable PitId { get; set; } +} + +public partial class DeletePitRequest +{ + public DeletePitRequest(IEnumerable pitId) : this(pitId?.ToArray()) { } + + public DeletePitRequest(params string[] pitId) => PitId = pitId; + + public IEnumerable PitId { get; set; } +} + +public partial class DeletePitDescriptor +{ + IEnumerable IDeletePitRequest.PitId { get; set; } + + public DeletePitDescriptor PitId(IEnumerable pitId) => + Assign(pitId?.ToArray(), (r, v) => r.PitId = v); + + public DeletePitDescriptor PitId(params string[] pitId) => + Assign(pitId, (r, v) => r.PitId = v); +} diff --git a/src/OpenSearch.Client/Search/PointInTime/DeletePitResponse.cs b/src/OpenSearch.Client/Search/PointInTime/DeletePitResponse.cs new file mode 100644 index 0000000000..7324c22e9b --- /dev/null +++ b/src/OpenSearch.Client/Search/PointInTime/DeletePitResponse.cs @@ -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 System.Collections.Generic; +using System.Runtime.Serialization; +using OpenSearch.Net; + +namespace OpenSearch.Client; + +[DataContract] +public class DeletePitResponse : ResponseBase +{ + [DataMember(Name = "pits")] + public IReadOnlyCollection Pits { get; internal set; } = EmptyReadOnly.Collection; +} + +[DataContract] +public class DeletedPit +{ + [DataMember(Name = "pit_id")] + public string PitId { get; set; } + + [DataMember(Name = "successful")] + public bool Successful { get; set; } +} diff --git a/src/OpenSearch.Client/Search/PointInTime/GetAllPitsRequest.cs b/src/OpenSearch.Client/Search/PointInTime/GetAllPitsRequest.cs new file mode 100644 index 0000000000..8a777b3463 --- /dev/null +++ b/src/OpenSearch.Client/Search/PointInTime/GetAllPitsRequest.cs @@ -0,0 +1,16 @@ +/* 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. +*/ + +namespace OpenSearch.Client; + +[MapsApi("get_all_pits")] +[ReadAs(typeof(GetAllPitsRequest))] +public partial interface IGetAllPitsRequest { } + +public partial class GetAllPitsRequest { } + +public partial class GetAllPitsDescriptor { } diff --git a/src/OpenSearch.Client/Search/PointInTime/GetAllPitsResponse.cs b/src/OpenSearch.Client/Search/PointInTime/GetAllPitsResponse.cs new file mode 100644 index 0000000000..a179c63f09 --- /dev/null +++ b/src/OpenSearch.Client/Search/PointInTime/GetAllPitsResponse.cs @@ -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 System.Collections.Generic; +using System.Runtime.Serialization; + +namespace OpenSearch.Client; + +[DataContract] +public class GetAllPitsResponse : ResponseBase +{ + [DataMember(Name = "pits")] + public IReadOnlyCollection Pits { get; internal set; } +} + +[DataContract] +public class PitDetail +{ + [DataMember(Name = "pit_id")] + public string PitId { get; internal set; } + + [DataMember(Name = "creation_time")] + public long CreationTime { get; internal set; } + + [DataMember(Name = "keep_alive")] + public long KeepAlive { get; internal set; } +} diff --git a/src/OpenSearch.Client/Search/Search/PointInTime/PointInTime.cs b/src/OpenSearch.Client/Search/Search/PointInTime/PointInTime.cs new file mode 100644 index 0000000000..53a8eb2aec --- /dev/null +++ b/src/OpenSearch.Client/Search/Search/PointInTime/PointInTime.cs @@ -0,0 +1,36 @@ +/* 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 System.Runtime.Serialization; + +namespace OpenSearch.Client; + +[ReadAs(typeof(PointInTime))] +public interface IPointInTime +{ + [DataMember(Name = "id")] + string Id { get; set; } + + [DataMember(Name = "keep_alive")] + Time KeepAlive { get; set; } +} + +public class PointInTime : IPointInTime +{ + public string Id { get; set; } + public Time KeepAlive { get; set; } +} + +public class PointInTimeDescriptor : DescriptorBase, IPointInTime +{ + string IPointInTime.Id { get; set; } + Time IPointInTime.KeepAlive { get; set; } + + public PointInTimeDescriptor Id(string id) => Assign(id, (a, v) => a.Id = v); + + public PointInTimeDescriptor KeepAlive(Time keepAlive) => Assign(keepAlive, (a, v) => a.KeepAlive = v); +} diff --git a/src/OpenSearch.Client/Search/Search/SearchRequest.cs b/src/OpenSearch.Client/Search/Search/SearchRequest.cs index e5863fed8d..47e688ed66 100644 --- a/src/OpenSearch.Client/Search/Search/SearchRequest.cs +++ b/src/OpenSearch.Client/Search/Search/SearchRequest.cs @@ -97,6 +97,17 @@ public partial interface ISearchRequest : ITypedSearchRequest [DataMember(Name = "min_score")] double? MinScore { get; set; } + /// + /// Search against a dataset frozen at a point-in-time (PIT) + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time/ + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + /// + /// + [DataMember(Name = "pit")] + IPointInTime PointInTime { get; set; } + /// /// Specify a query to apply to the search hits at the very end of a search request, /// after aggregations have already been calculated. Useful when both search hits and aggregations @@ -240,6 +251,8 @@ public partial class SearchRequest /// public double? MinScore { get; set; } /// + public IPointInTime PointInTime { get; set; } + /// public QueryContainer PostFilter { get; set; } /// public bool? Profile { get; set; } @@ -285,10 +298,7 @@ public partial class SearchRequest protected sealed override void RequestDefaults(SearchRequestParameters parameters) => TypedKeys = true; - protected override string ResolveUrl(RouteValues routeValues, IConnectionSettingsValues settings) - { - return base.ResolveUrl(routeValues, settings); - } + protected override string ResolveUrl(RouteValues routeValues, IConnectionSettingsValues settings) => base.ResolveUrl(routeValues, settings); } [DataContract] @@ -318,6 +328,7 @@ public partial class SearchDescriptor where TInferDocument : cla IHighlight ISearchRequest.Highlight { get; set; } IDictionary ISearchRequest.IndicesBoost { get; set; } double? ISearchRequest.MinScore { get; set; } + IPointInTime ISearchRequest.PointInTime { get; set; } QueryContainer ISearchRequest.PostFilter { get; set; } bool? ISearchRequest.Profile { get; set; } QueryContainer ISearchRequest.Query { get; set; } @@ -519,9 +530,14 @@ public SearchDescriptor RuntimeFields(Func RuntimeFields(Func, IPromise> runtimeFieldsSelector) where TSource : class => Assign(runtimeFieldsSelector, (a, v) => a.RuntimeFields = v?.Invoke(new RuntimeFieldsDescriptor())?.Value); - protected override string ResolveUrl(RouteValues routeValues, IConnectionSettingsValues settings) - { - return base.ResolveUrl(routeValues, settings); - } + /// + public SearchDescriptor PointInTime(Func selector) => + Assign(selector, (a, v) => + { + a.PointInTime = v?.Invoke(new PointInTimeDescriptor()); + if (a.PointInTime != null) a.RouteValues.Remove("index"); + }); + + protected override string ResolveUrl(RouteValues routeValues, IConnectionSettingsValues settings) => base.ResolveUrl(routeValues, settings); } } diff --git a/src/OpenSearch.Client/_Generated/ApiUrlsLookup.cs b/src/OpenSearch.Client/_Generated/ApiUrlsLookup.cs new file mode 100644 index 0000000000..da842e9799 --- /dev/null +++ b/src/OpenSearch.Client/_Generated/ApiUrlsLookup.cs @@ -0,0 +1,60 @@ +/* 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. +*/ +/* +* Modifications Copyright OpenSearch Contributors. See +* GitHub history for details. +* +* Licensed to Elasticsearch B.V. under one or more contributor +* license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright +* ownership. Elasticsearch B.V. licenses this file to you under +* the Apache License, Version 2.0 (the "License"); you may +* not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ----------------------------------------------- +// +// This file is automatically generated +// Please do not edit these files manually +// Run the following in the root of the repos: +// +// *NIX : ./build.sh codegen +// Windows : build.bat codegen +// +// ----------------------------------------------- +namespace OpenSearch.Client +{ + internal static partial class ApiUrlsLookups + { + internal static readonly ApiUrls NoNamespaceCreatePit = + new(new[] { "{index}/_search/point_in_time" }); + + internal static readonly ApiUrls NoNamespaceDeleteAllPits = + new(new[] { "_search/point_in_time/_all" }); + + internal static readonly ApiUrls NoNamespaceDeletePit = + new(new[] { "_search/point_in_time" }); + + internal static readonly ApiUrls NoNamespaceGetAllPits = + new(new[] { "_search/point_in_time/_all" }); + } +} diff --git a/src/OpenSearch.Client/_Generated/ApiUrlsLookup.generated.cs b/src/OpenSearch.Client/_Generated/ApiUrlsLookup.generated.cs index d6a9e31f3f..6336f9b211 100644 --- a/src/OpenSearch.Client/_Generated/ApiUrlsLookup.generated.cs +++ b/src/OpenSearch.Client/_Generated/ApiUrlsLookup.generated.cs @@ -28,7 +28,7 @@ namespace OpenSearch.Client { - internal static class ApiUrlsLookups + internal static partial class ApiUrlsLookups { internal static ApiUrls NoNamespaceBulk = new ApiUrls(new[]{"_bulk", "{index}/_bulk"}); internal static ApiUrls CatAliases = new ApiUrls(new[]{"_cat/aliases", "_cat/aliases/{name}"}); diff --git a/src/OpenSearch.Client/_Generated/Descriptors.NoNamespace.cs b/src/OpenSearch.Client/_Generated/Descriptors.NoNamespace.cs new file mode 100644 index 0000000000..3eb30c27c2 --- /dev/null +++ b/src/OpenSearch.Client/_Generated/Descriptors.NoNamespace.cs @@ -0,0 +1,154 @@ +/* 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. +*/ +/* +* Modifications Copyright OpenSearch Contributors. See +* GitHub history for details. +* +* Licensed to Elasticsearch B.V. under one or more contributor +* license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright +* ownership. Elasticsearch B.V. licenses this file to you under +* the Apache License, Version 2.0 (the "License"); you may +* not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ----------------------------------------------- +// +// This file is automatically generated +// Please do not edit these files manually +// Run the following in the root of the repos: +// +// *NIX : ./build.sh codegen +// Windows : build.bat codegen +// +// ----------------------------------------------- +// ReSharper disable RedundantUsingDirective +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Linq.Expressions; + +using OpenSearch.Net; +using OpenSearch.Net.Utf8Json; + +// ReSharper disable RedundantBaseConstructorCall +// ReSharper disable UnusedTypeParameter +// ReSharper disable PartialMethodWithSinglePart +// ReSharper disable RedundantNameQualifier +namespace OpenSearch.Client +{ + /// Descriptor for CreatePit https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#create-a-pit + public partial class CreatePitDescriptor + : RequestDescriptorBase, + ICreatePitRequest + { + internal override ApiUrls ApiUrls => ApiUrlsLookups.NoNamespaceCreatePit; + + /// /{index}/_search/point_in_time + /// this parameter is required + public CreatePitDescriptor(Indices index) + : base(r => r.Required("index", index)) { } + + /// Used for serialization purposes, making sure we have a parameterless constructor + [SerializationConstructor] + protected CreatePitDescriptor() + : base() { } + + // values part of the url path + Indices ICreatePitRequest.Index => Self.RouteValues.Get("index"); + + /// Comma-separated list of indices; use the special string `_all` or Indices.All to perform the operation on all indices. + public CreatePitDescriptor Index(Indices index) => + Assign(index, (a, v) => a.RouteValues.Required("index", v)); + + /// a shortcut into calling Index(typeof(TOther)) + public CreatePitDescriptor Index() + where TOther : class => + Assign(typeof(TOther), (a, v) => a.RouteValues.Required("index", (Indices)v)); + + /// A shortcut into calling Index(Indices.All) + public CreatePitDescriptor AllIndices() => Index(Indices.All); + + // Request parameters + /// Allow if point in time can be created with partial failures. + public CreatePitDescriptor AllowPartialPitCreation(bool? allowpartialpitcreation = true) => + Qs("allow_partial_pit_creation", allowpartialpitcreation); + + /// Whether to expand wildcard expression to concrete indices that are open, closed or both. + public CreatePitDescriptor ExpandWildcards(ExpandWildcards? expandwildcards) => + Qs("expand_wildcards", expandwildcards); + + /// Specify the keep alive for point in time. + public CreatePitDescriptor KeepAlive(Time keepalive) => Qs("keep_alive", keepalive); + + /// Specify the node or shard the operation should be performed on. + public CreatePitDescriptor Preference(string preference) => Qs("preference", preference); + + /// + /// A document is routed to a particular shard in an index using the following formula + /// shard_num = hash(_routing) % num_primary_shards + /// OpenSearch will use the document id if not provided. + /// For requests that are constructed from/for a document OpenSearch.Client will automatically infer the routing key + /// if that document has a or a routing mapping on for its type exists on + /// + public CreatePitDescriptor Routing(Routing routing) => Qs("routing", routing); + } + + /// Descriptor for DeleteAllPits https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#delete-pits + public partial class DeleteAllPitsDescriptor + : RequestDescriptorBase< + DeleteAllPitsDescriptor, + DeleteAllPitsRequestParameters, + IDeleteAllPitsRequest + >, + IDeleteAllPitsRequest + { + internal override ApiUrls ApiUrls => ApiUrlsLookups.NoNamespaceDeleteAllPits; + // values part of the url path + // Request parameters + } + + /// Descriptor for DeletePit https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#delete-pits + public partial class DeletePitDescriptor + : RequestDescriptorBase, + IDeletePitRequest + { + internal override ApiUrls ApiUrls => ApiUrlsLookups.NoNamespaceDeletePit; + // values part of the url path + // Request parameters + } + + /// Descriptor for GetAllPits https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#list-all-pits + public partial class GetAllPitsDescriptor + : RequestDescriptorBase< + GetAllPitsDescriptor, + GetAllPitsRequestParameters, + IGetAllPitsRequest + >, + IGetAllPitsRequest + { + internal override ApiUrls ApiUrls => ApiUrlsLookups.NoNamespaceGetAllPits; + // values part of the url path + // Request parameters + } +} diff --git a/src/OpenSearch.Client/_Generated/IOpenSearchClient.cs b/src/OpenSearch.Client/_Generated/IOpenSearchClient.cs new file mode 100644 index 0000000000..d38dd2f359 --- /dev/null +++ b/src/OpenSearch.Client/_Generated/IOpenSearchClient.cs @@ -0,0 +1,219 @@ +/* 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. +*/ +/* +* Modifications Copyright OpenSearch Contributors. See +* GitHub history for details. +* +* Licensed to Elasticsearch B.V. under one or more contributor +* license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright +* ownership. Elasticsearch B.V. licenses this file to you under +* the Apache License, Version 2.0 (the "License"); you may +* not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ----------------------------------------------- +// +// This file is automatically generated +// Please do not edit these files manually +// Run the following in the root of the repos: +// +// *NIX : ./build.sh codegen +// Windows : build.bat codegen +// +// ----------------------------------------------- +// ReSharper disable RedundantUsingDirective +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using System.Linq; +using OpenSearch.Client; + +namespace OpenSearch.Client +{ + /// + /// OpenSearch high level client + /// + public partial interface IOpenSearchClient + { + /// + /// POST request to the create_pit API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#create-a-pit + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + CreatePitResponse CreatePit( + Indices index, + Func selector = null + ); + + /// + /// POST request to the create_pit API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#create-a-pit + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + Task CreatePitAsync( + Indices index, + Func selector = null, + CancellationToken ct = default + ); + + /// + /// POST request to the create_pit API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#create-a-pit + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + CreatePitResponse CreatePit(ICreatePitRequest request); + + /// + /// POST request to the create_pit API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#create-a-pit + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + Task CreatePitAsync( + ICreatePitRequest request, + CancellationToken ct = default + ); + + /// + /// DELETE request to the delete_all_pits API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#delete-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + DeleteAllPitsResponse DeleteAllPits( + Func selector = null + ); + + /// + /// DELETE request to the delete_all_pits API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#delete-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + Task DeleteAllPitsAsync( + Func selector = null, + CancellationToken ct = default + ); + + /// + /// DELETE request to the delete_all_pits API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#delete-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + DeleteAllPitsResponse DeleteAllPits(IDeleteAllPitsRequest request); + + /// + /// DELETE request to the delete_all_pits API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#delete-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + Task DeleteAllPitsAsync( + IDeleteAllPitsRequest request, + CancellationToken ct = default + ); + + /// + /// DELETE request to the delete_pit API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#delete-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + DeletePitResponse DeletePit(Func selector = null); + + /// + /// DELETE request to the delete_pit API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#delete-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + Task DeletePitAsync( + Func selector = null, + CancellationToken ct = default + ); + + /// + /// DELETE request to the delete_pit API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#delete-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + DeletePitResponse DeletePit(IDeletePitRequest request); + + /// + /// DELETE request to the delete_pit API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#delete-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + Task DeletePitAsync( + IDeletePitRequest request, + CancellationToken ct = default + ); + + /// + /// GET request to the get_all_pits API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#list-all-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + GetAllPitsResponse GetAllPits( + Func selector = null + ); + + /// + /// GET request to the get_all_pits API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#list-all-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + Task GetAllPitsAsync( + Func selector = null, + CancellationToken ct = default + ); + + /// + /// GET request to the get_all_pits API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#list-all-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + GetAllPitsResponse GetAllPits(IGetAllPitsRequest request); + + /// + /// GET request to the get_all_pits API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#list-all-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + Task GetAllPitsAsync( + IGetAllPitsRequest request, + CancellationToken ct = default + ); + } +} diff --git a/src/OpenSearch.Client/_Generated/OpenSearchClient.cs b/src/OpenSearch.Client/_Generated/OpenSearchClient.cs new file mode 100644 index 0000000000..e579b1e86b --- /dev/null +++ b/src/OpenSearch.Client/_Generated/OpenSearchClient.cs @@ -0,0 +1,247 @@ +/* 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. +*/ +/* +* Modifications Copyright OpenSearch Contributors. See +* GitHub history for details. +* +* Licensed to Elasticsearch B.V. under one or more contributor +* license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright +* ownership. Elasticsearch B.V. licenses this file to you under +* the Apache License, Version 2.0 (the "License"); you may +* not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ----------------------------------------------- +// +// This file is automatically generated +// Please do not edit these files manually +// Run the following in the root of the repos: +// +// *NIX : ./build.sh codegen +// Windows : build.bat codegen +// +// ----------------------------------------------- +// ReSharper disable RedundantUsingDirective +using System; +using System.Threading; +using System.Threading.Tasks; +using OpenSearch.Client; + +// ReSharper disable RedundantTypeArgumentsOfMethod +namespace OpenSearch.Client +{ + /// + /// OpenSearch high level client + /// + public partial class OpenSearchClient : IOpenSearchClient + { + /// + /// POST request to the create_pit API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#create-a-pit + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + public CreatePitResponse CreatePit( + Indices index, + Func selector = null + ) => CreatePit(selector.InvokeOrDefault(new CreatePitDescriptor(index: index))); + + /// + /// POST request to the create_pit API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#create-a-pit + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + public Task CreatePitAsync( + Indices index, + Func selector = null, + CancellationToken ct = default + ) => CreatePitAsync(selector.InvokeOrDefault(new CreatePitDescriptor(index: index)), ct); + + /// + /// POST request to the create_pit API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#create-a-pit + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + public CreatePitResponse CreatePit(ICreatePitRequest request) => + DoRequest(request, request.RequestParameters); + + /// + /// POST request to the create_pit API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#create-a-pit + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + public Task CreatePitAsync( + ICreatePitRequest request, + CancellationToken ct = default + ) => + DoRequestAsync( + request, + request.RequestParameters, + ct + ); + + /// + /// DELETE request to the delete_all_pits API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#delete-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + public DeleteAllPitsResponse DeleteAllPits( + Func selector = null + ) => DeleteAllPits(selector.InvokeOrDefault(new DeleteAllPitsDescriptor())); + + /// + /// DELETE request to the delete_all_pits API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#delete-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + public Task DeleteAllPitsAsync( + Func selector = null, + CancellationToken ct = default + ) => DeleteAllPitsAsync(selector.InvokeOrDefault(new DeleteAllPitsDescriptor()), ct); + + /// + /// DELETE request to the delete_all_pits API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#delete-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + public DeleteAllPitsResponse DeleteAllPits(IDeleteAllPitsRequest request) => + DoRequest( + request, + request.RequestParameters + ); + + /// + /// DELETE request to the delete_all_pits API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#delete-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + public Task DeleteAllPitsAsync( + IDeleteAllPitsRequest request, + CancellationToken ct = default + ) => + DoRequestAsync( + request, + request.RequestParameters, + ct + ); + + /// + /// DELETE request to the delete_pit API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#delete-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + public DeletePitResponse DeletePit( + Func selector = null + ) => DeletePit(selector.InvokeOrDefault(new DeletePitDescriptor())); + + /// + /// DELETE request to the delete_pit API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#delete-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + public Task DeletePitAsync( + Func selector = null, + CancellationToken ct = default + ) => DeletePitAsync(selector.InvokeOrDefault(new DeletePitDescriptor()), ct); + + /// + /// DELETE request to the delete_pit API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#delete-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + public DeletePitResponse DeletePit(IDeletePitRequest request) => + DoRequest(request, request.RequestParameters); + + /// + /// DELETE request to the delete_pit API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#delete-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + public Task DeletePitAsync( + IDeletePitRequest request, + CancellationToken ct = default + ) => + DoRequestAsync( + request, + request.RequestParameters, + ct + ); + + /// + /// GET request to the get_all_pits API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#list-all-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + public GetAllPitsResponse GetAllPits( + Func selector = null + ) => GetAllPits(selector.InvokeOrDefault(new GetAllPitsDescriptor())); + + /// + /// GET request to the get_all_pits API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#list-all-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + public Task GetAllPitsAsync( + Func selector = null, + CancellationToken ct = default + ) => GetAllPitsAsync(selector.InvokeOrDefault(new GetAllPitsDescriptor()), ct); + + /// + /// GET request to the get_all_pits API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#list-all-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + public GetAllPitsResponse GetAllPits(IGetAllPitsRequest request) => + DoRequest(request, request.RequestParameters); + + /// + /// GET request to the get_all_pits API, read more about this API online: + /// + /// https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#list-all-pits + /// + /// Supported by OpenSearch servers of version 2.4.0 or greater. + public Task GetAllPitsAsync( + IGetAllPitsRequest request, + CancellationToken ct = default + ) => + DoRequestAsync( + request, + request.RequestParameters, + ct + ); + } +} diff --git a/src/OpenSearch.Client/_Generated/Requests.NoNamespace.cs b/src/OpenSearch.Client/_Generated/Requests.NoNamespace.cs new file mode 100644 index 0000000000..5ab1abdbcd --- /dev/null +++ b/src/OpenSearch.Client/_Generated/Requests.NoNamespace.cs @@ -0,0 +1,177 @@ +/* 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. +*/ +/* +* Modifications Copyright OpenSearch Contributors. See +* GitHub history for details. +* +* Licensed to Elasticsearch B.V. under one or more contributor +* license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright +* ownership. Elasticsearch B.V. licenses this file to you under +* the Apache License, Version 2.0 (the "License"); you may +* not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ----------------------------------------------- +// +// This file is automatically generated +// Please do not edit these files manually +// Run the following in the root of the repos: +// +// *NIX : ./build.sh codegen +// Windows : build.bat codegen +// +// ----------------------------------------------- +// ReSharper disable RedundantUsingDirective +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Linq.Expressions; +using System.Runtime.Serialization; +using OpenSearch.Net; +using OpenSearch.Net.Utf8Json; + +// ReSharper disable RedundantBaseConstructorCall +// ReSharper disable UnusedTypeParameter +// ReSharper disable PartialMethodWithSinglePart +// ReSharper disable RedundantNameQualifier +namespace OpenSearch.Client +{ + [InterfaceDataContract] + public partial interface ICreatePitRequest : IRequest + { + [IgnoreDataMember] + Indices Index { get; } + } + + /// Request for CreatePit https://opensearch.org/docs/latest/search-plugins/point-in-time-api/#create-a-pit + public partial class CreatePitRequest + : PlainRequestBase, + ICreatePitRequest + { + protected ICreatePitRequest Self => this; + internal override ApiUrls ApiUrls => ApiUrlsLookups.NoNamespaceCreatePit; + + /// /{index}/_search/point_in_time + /// this parameter is required + public CreatePitRequest(Indices index) + : base(r => r.Required("index", index)) { } + + /// Used for serialization purposes, making sure we have a parameterless constructor + [SerializationConstructor] + protected CreatePitRequest() + : base() { } + + // values part of the url path + [IgnoreDataMember] + Indices ICreatePitRequest.Index => Self.RouteValues.Get("index"); + + // Request parameters + /// Allow if point in time can be created with partial failures. + public bool? AllowPartialPitCreation + { + get => Q("allow_partial_pit_creation"); + set => Q("allow_partial_pit_creation", value); + } + + /// Whether to expand wildcard expression to concrete indices that are open, closed or both. + public ExpandWildcards? ExpandWildcards + { + get => Q("expand_wildcards"); + set => Q("expand_wildcards", value); + } + + /// Specify the keep alive for point in time. + public Time KeepAlive + { + get => Q