-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathDeleteByQueryDescriptor.cs
94 lines (71 loc) · 3.08 KB
/
DeleteByQueryDescriptor.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using System.Linq;
using Elasticsearch.Net;
using Newtonsoft.Json;
namespace Nest
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public interface IDeleteByQueryRequest : IQueryPath<DeleteByQueryRequestParameters>
{
[JsonProperty("query")]
IQueryContainer Query { get; set; }
}
public interface IDeleteByQueryRequest<T> : IDeleteByQueryRequest where T : class {}
internal static class DeleteByQueryPathInfo
{
public static void Update(ElasticsearchPathInfo<DeleteByQueryRequestParameters> pathInfo, IDeleteByQueryRequest request)
{
pathInfo.HttpMethod = PathInfoHttpMethod.DELETE;
//query works a bit different in that if all types and all indices are specified the root
//needs to be /_all/_query not just /_query
if (pathInfo.Index.IsNullOrEmpty() && pathInfo.Type.IsNullOrEmpty()
&& request.AllIndices.GetValueOrDefault(false)
&& request.AllTypes.GetValueOrDefault(false))
pathInfo.Index = "_all";
}
}
public partial class DeleteByQueryRequest : QueryPathBase<DeleteByQueryRequestParameters>, IDeleteByQueryRequest
{
public DeleteByQueryRequest() {}
public DeleteByQueryRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }
public DeleteByQueryRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }
public IQueryContainer Query { get; set; }
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<DeleteByQueryRequestParameters> pathInfo)
{
DeleteByQueryPathInfo.Update(pathInfo, this);
}
}
public partial class DeleteByQueryRequest<T> : QueryPathBase<DeleteByQueryRequestParameters, T>, IDeleteByQueryRequest where T : class
{
public DeleteByQueryRequest() {}
public DeleteByQueryRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }
public DeleteByQueryRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }
public IQueryContainer Query { get; set; }
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<DeleteByQueryRequestParameters> pathInfo)
{
DeleteByQueryPathInfo.Update(pathInfo, this);
}
}
public partial class DeleteByQueryDescriptor<T>
: QueryPathDescriptorBase<DeleteByQueryDescriptor<T>, DeleteByQueryRequestParameters, T>, IDeleteByQueryRequest
where T : class
{
private IDeleteByQueryRequest Self { get { return this; } }
IQueryContainer IDeleteByQueryRequest.Query { get; set; }
public DeleteByQueryDescriptor<T> MatchAll()
{
Self.Query = new QueryDescriptor<T>().MatchAll();
return this;
}
public DeleteByQueryDescriptor<T> Query(Func<QueryDescriptor<T>, QueryContainer> querySelector)
{
Self.Query = querySelector(new QueryDescriptor<T>());
return this;
}
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<DeleteByQueryRequestParameters> pathInfo)
{
DeleteByQueryPathInfo.Update(pathInfo, this);
}
}
}