From abcb7ead032fd1e4e0beaccd43ae6fa984464398 Mon Sep 17 00:00:00 2001 From: Florian Bernd Date: Wed, 10 Jul 2024 09:51:28 +0200 Subject: [PATCH] Implement common request query parameters for request descriptors (#8257) --- .../Core/Request/PlainRequest.cs | 14 +++++++------- .../Core/Request/Request.cs | 4 ++-- .../Core/Request/RequestDescriptor.cs | 19 ++++++++++++++++++- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/Elastic.Clients.Elasticsearch.Shared/Core/Request/PlainRequest.cs b/src/Elastic.Clients.Elasticsearch.Shared/Core/Request/PlainRequest.cs index ea8c67aded5..912d1a46dbd 100644 --- a/src/Elastic.Clients.Elasticsearch.Shared/Core/Request/PlainRequest.cs +++ b/src/Elastic.Clients.Elasticsearch.Shared/Core/Request/PlainRequest.cs @@ -30,12 +30,12 @@ public bool? ErrorTrace } /// - /// A comma-separated list of filters used to reduce the response. - /// - /// Use of response filtering can result in a response from Elasticsearch - /// that cannot be correctly deserialized to the respective response type for the request. - /// In such situations, use the low level client to issue the request and handle response deserialization. - /// + /// A list of filters used to reduce the response. + /// + /// Use of response filtering can result in a response from Elasticsearch + /// that cannot be correctly deserialized to the respective response type for the request. + /// In such situations, use the low level client to issue the request and handle response deserialization. + /// /// [JsonIgnore] public string[] FilterPath @@ -44,7 +44,7 @@ public string[] FilterPath set => Q("filter_path", value); } - ///Return human readable values for statistics. + ///Return human-readable values for statistics. [JsonIgnore] public bool? Human { diff --git a/src/Elastic.Clients.Elasticsearch.Shared/Core/Request/Request.cs b/src/Elastic.Clients.Elasticsearch.Shared/Core/Request/Request.cs index adb0ba6ea57..2b643379e60 100644 --- a/src/Elastic.Clients.Elasticsearch.Shared/Core/Request/Request.cs +++ b/src/Elastic.Clients.Elasticsearch.Shared/Core/Request/Request.cs @@ -80,9 +80,9 @@ protected Request(Func pathSelector) [JsonIgnore] internal TParameters RequestParameters => _parameters; - protected TOut Q(string name) => RequestParameters.GetQueryStringValue(name); + protected TOut? Q(string name) => RequestParameters.GetQueryStringValue(name); - protected void Q(string name, object value) => RequestParameters.SetQueryString(name, value); + protected void Q(string name, object? value) => RequestParameters.SetQueryString(name, value); protected void Q(string name, IStringable value) => RequestParameters.SetQueryString(name, value.GetString()); diff --git a/src/Elastic.Clients.Elasticsearch.Shared/Core/Request/RequestDescriptor.cs b/src/Elastic.Clients.Elasticsearch.Shared/Core/Request/RequestDescriptor.cs index 2fd99ba8f23..77ad327e1f5 100644 --- a/src/Elastic.Clients.Elasticsearch.Shared/Core/Request/RequestDescriptor.cs +++ b/src/Elastic.Clients.Elasticsearch.Shared/Core/Request/RequestDescriptor.cs @@ -5,6 +5,7 @@ using System; using System.ComponentModel; using System.Text.Json; + #if ELASTICSEARCH_SERVERLESS using Elastic.Clients.Elasticsearch.Serverless.Serialization; #else @@ -40,7 +41,7 @@ internal RequestDescriptor(Func pathSelector) : base(p protected TDescriptor Self => _descriptor; - protected TDescriptor Qs(string name, object value) + protected TDescriptor Qs(string name, object? value) { Q(name, value); return _descriptor; @@ -64,6 +65,22 @@ public TDescriptor RequestConfiguration( return _descriptor; } + /// + /// A list of filters used to reduce the response. + /// + /// Use of response filtering can result in a response from Elasticsearch + /// that cannot be correctly deserialized to the respective response type for the request. + /// In such situations, use the low level client to issue the request and handle response deserialization. + /// + /// + public TDescriptor FilterPath(params string[] value) => Qs("filter_path", value); + + ///Return human-readable values for statistics. + public TDescriptor Human(bool? value) => Qs("human", value); + + ///Pretty format the returned JSON response. + public TDescriptor Pretty(bool? value) => Qs("pretty", value); + /// /// Hides the method. ///