-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathIndexRequest.cs
42 lines (31 loc) · 1.48 KB
/
IndexRequest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
using System.Text.Json.Serialization;
#if ELASTICSEARCH_SERVERLESS
using Elastic.Clients.Elasticsearch.Serverless.Requests;
#else
using Elastic.Clients.Elasticsearch.Requests;
#endif
using Elastic.Transport;
#if ELASTICSEARCH_SERVERLESS
namespace Elastic.Clients.Elasticsearch.Serverless;
#else
namespace Elastic.Clients.Elasticsearch;
#endif
public partial class IndexRequest<TDocument>
{
public IndexRequest() : this(typeof(TDocument)) { }
public IndexRequest(TDocument document, Id id) : this(typeof(TDocument), id) => Document = document;
protected override HttpMethod? DynamicHttpMethod => GetHttpMethod(this);
public IndexRequest(TDocument document, IndexName index = null, Id id = null) : this(index ?? typeof(TDocument), id ?? Id.From(document)) => Document = document;
internal Request<IndexRequestParameters> Self => this;
[JsonIgnore] private Id? Id => RouteValues.Get<Id>("id");
internal static HttpMethod GetHttpMethod(IndexRequest<TDocument> request) =>
request.Id?.StringOrLongValue != null || request.RouteValues.ContainsId ? HttpMethod.PUT : HttpMethod.POST;
}
public sealed partial class IndexRequestDescriptor<TDocument>
{
internal Id _id;
protected override HttpMethod? DynamicHttpMethod => _id is not null || RouteValues.ContainsId ? HttpMethod.PUT : HttpMethod.POST;
}