Skip to content

Commit 0d2c6ed

Browse files
committed
Expose q querystring parameter on search (#4238)
* remove q from block list on SearchOverrides * Expose ?q as QueryOnQueryString for search like its exposed on other API's as well' * eventhough we expose q on query string it should not trigger GET as we always end up sending other params in the body (cherry picked from commit fc1b74a)
1 parent db00f02 commit 0d2c6ed

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

src/CodeGeneration/ApiGenerator/Configuration/Overrides/Endpoints/SearchOverrides.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public class SearchOverrides : EndpointOverridesBase
1212
"timeout",
1313
"explain",
1414
"version",
15-
"q", //we dont support GET searches
1615
"sort",
1716
"_source",
1817
"_source_includes",

src/Elasticsearch.Net/Api/RequestParameters/RequestParameters.NoNamespace.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,13 @@ public string Preference
16381638
set => Q("preference", value);
16391639
}
16401640

1641+
///<summary>Query in the Lucene query string syntax</summary>
1642+
public string QueryOnQueryString
1643+
{
1644+
get => Q<string>("q");
1645+
set => Q("q", value);
1646+
}
1647+
16411648
///<summary>Specify if request cache should be used for this request or not, defaults to index level setting</summary>
16421649
public bool? RequestCache
16431650
{

src/Nest/Descriptors.NoNamespace.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,8 @@ public SearchDescriptor<TInferDocument> Index<TOther>()
12721272
public SearchDescriptor<TInferDocument> PreFilterShardSize(long? prefiltershardsize) => Qs("pre_filter_shard_size", prefiltershardsize);
12731273
///<summary>Specify the node or shard the operation should be performed on (default: random)</summary>
12741274
public SearchDescriptor<TInferDocument> Preference(string preference) => Qs("preference", preference);
1275+
///<summary>Query in the Lucene query string syntax</summary>
1276+
public SearchDescriptor<TInferDocument> QueryOnQueryString(string queryonquerystring) => Qs("q", queryonquerystring);
12751277
///<summary>Specify if request cache should be used for this request or not, defaults to index level setting</summary>
12761278
public SearchDescriptor<TInferDocument> RequestCache(bool? requestcache = true) => Qs("request_cache", requestcache);
12771279
///<summary>

src/Nest/Requests.NoNamespace.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2743,6 +2743,13 @@ public string Preference
27432743
set => Q("preference", value);
27442744
}
27452745

2746+
///<summary>Query in the Lucene query string syntax</summary>
2747+
public string QueryOnQueryString
2748+
{
2749+
get => Q<string>("q");
2750+
set => Q("q", value);
2751+
}
2752+
27462753
///<summary>Specify if request cache should be used for this request or not, defaults to index level setting</summary>
27472754
public bool? RequestCache
27482755
{

src/Nest/Search/Search/SearchRequest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public partial interface ISearchRequest : ITypedSearchRequest
155155
/// </summary>
156156
[DataMember(Name = "track_scores")]
157157
bool? TrackScores { get; set; }
158-
158+
159159
/// <summary>
160160
/// Return a version for each search hit
161161
/// </summary>
@@ -224,7 +224,7 @@ public partial class SearchRequest
224224
public bool? Version { get; set; }
225225

226226
protected override HttpMethod HttpMethod =>
227-
RequestState.RequestParameters?.ContainsQueryString("source") == true || RequestState.RequestParameters?.ContainsQueryString("q") == true
227+
RequestState.RequestParameters?.ContainsQueryString("source") == true
228228
? HttpMethod.GET
229229
: HttpMethod.POST;
230230

@@ -246,7 +246,7 @@ public partial class SearchRequest<TInferDocument> : ISearchRequest<TInferDocume
246246
public partial class SearchDescriptor<TInferDocument> where TInferDocument : class
247247
{
248248
protected override HttpMethod HttpMethod =>
249-
RequestState.RequestParameters?.ContainsQueryString("source") == true || RequestState.RequestParameters?.ContainsQueryString("q") == true
249+
RequestState.RequestParameters?.ContainsQueryString("source") == true
250250
? HttpMethod.GET
251251
: HttpMethod.POST;
252252

0 commit comments

Comments
 (0)