|
1 | | -using System; |
2 | | -using System.Collections.Generic; |
3 | | -using System.Linq; |
4 | | -using System.Text; |
5 | | -using Elasticsearch.Net; |
6 | | -using Newtonsoft.Json; |
7 | | -using Newtonsoft.Json.Converters; |
8 | | -using Nest.Resolvers.Converters; |
9 | | - |
10 | | -using Nest.Resolvers; |
11 | | - |
12 | | -namespace Nest |
13 | | -{ |
14 | | - |
15 | | - /// <summary> |
16 | | - /// Provides a base for descriptors that need to describe a path in the form of |
17 | | - /// <pre> |
18 | | - /// /{index}/{type} |
19 | | - /// </pre> |
20 | | - /// Where neither parameter is optional |
21 | | - /// </summary> |
22 | | - public class IndexTypePathDescriptor<TDescriptor, TParameters> : BasePathDescriptor<TDescriptor> |
23 | | - where TDescriptor : IndexTypePathDescriptor<TDescriptor, TParameters>, new() |
24 | | - where TParameters : FluentRequestParameters<TParameters>, new() |
25 | | - { |
26 | | - internal IndexNameMarker _Index { get; set; } |
27 | | - internal TypeNameMarker _Type { get; set; } |
28 | | - |
29 | | - public TDescriptor Index<TAlternative>() where TAlternative : class |
30 | | - { |
31 | | - this._Index = typeof(TAlternative); |
32 | | - return (TDescriptor)this; |
33 | | - } |
34 | | - |
35 | | - public TDescriptor Index(string index) |
36 | | - { |
37 | | - this._Index = index; |
38 | | - return (TDescriptor)this; |
39 | | - } |
40 | | - |
41 | | - public TDescriptor Index(Type indexType) |
42 | | - { |
43 | | - this._Index = indexType; |
44 | | - return (TDescriptor)this; |
45 | | - } |
46 | | - |
47 | | - public TDescriptor Type<TAlternative>() where TAlternative : class |
48 | | - { |
49 | | - this._Type = typeof(TAlternative); |
50 | | - return (TDescriptor)this; |
51 | | - } |
52 | | - |
53 | | - public TDescriptor Type(string type) |
54 | | - { |
55 | | - this._Type = type; |
56 | | - return (TDescriptor)this; |
57 | | - } |
58 | | - |
59 | | - public TDescriptor Type(Type type) |
60 | | - { |
61 | | - this._Type = type; |
62 | | - return (TDescriptor)this; |
63 | | - } |
64 | | - |
65 | | - internal virtual ElasticsearchPathInfo<TParameters> ToPathInfo(IConnectionSettingsValues settings, TParameters queryString) |
66 | | - { |
67 | | - var inferrer = new ElasticInferrer(settings); |
68 | | - if (this._Index == null) |
69 | | - throw new DslException("Index() not specified"); |
70 | | - if (this._Type == null) |
71 | | - throw new DslException("Type() not specified"); |
72 | | - |
73 | | - var index = new ElasticInferrer(settings).IndexName(this._Index); |
74 | | - var type = new ElasticInferrer(settings).TypeName(this._Type); |
75 | | - var pathInfo = new ElasticsearchPathInfo<TParameters>() |
76 | | - { |
77 | | - Index = index, |
78 | | - Type = type |
79 | | - }; |
80 | | - pathInfo.RequestParameters = queryString ?? new TParameters(); |
81 | | - pathInfo.RequestParameters.RequestConfiguration(r=>this._RequestConfiguration); |
82 | | - return pathInfo; |
83 | | - } |
84 | | - |
85 | | - } |
86 | | -} |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using Elasticsearch.Net; |
| 6 | +using Newtonsoft.Json; |
| 7 | +using Newtonsoft.Json.Converters; |
| 8 | +using Nest.Resolvers.Converters; |
| 9 | + |
| 10 | +using Nest.Resolvers; |
| 11 | + |
| 12 | +namespace Nest |
| 13 | +{ |
| 14 | + |
| 15 | + /// <summary> |
| 16 | + /// Provides a base for descriptors that need to describe a path in the form of |
| 17 | + /// <pre> |
| 18 | + /// /{index}/{type} |
| 19 | + /// </pre> |
| 20 | + /// Where neither parameter is optional |
| 21 | + /// </summary> |
| 22 | + public class IndexTypePathDescriptor<TDescriptor, TParameters> : BasePathDescriptor<TDescriptor> |
| 23 | + where TDescriptor : IndexTypePathDescriptor<TDescriptor, TParameters>, new() |
| 24 | + where TParameters : FluentRequestParameters<TParameters>, new() |
| 25 | + { |
| 26 | + internal IndexNameMarker _Index { get; set; } |
| 27 | + internal TypeNameMarker _Type { get; set; } |
| 28 | + |
| 29 | + public TDescriptor Index<TAlternative>() where TAlternative : class |
| 30 | + { |
| 31 | + this._Index = typeof(TAlternative); |
| 32 | + return (TDescriptor)this; |
| 33 | + } |
| 34 | + |
| 35 | + public TDescriptor Index(string index) |
| 36 | + { |
| 37 | + this._Index = index; |
| 38 | + return (TDescriptor)this; |
| 39 | + } |
| 40 | + |
| 41 | + public TDescriptor Index(Type indexType) |
| 42 | + { |
| 43 | + this._Index = indexType; |
| 44 | + return (TDescriptor)this; |
| 45 | + } |
| 46 | + |
| 47 | + public TDescriptor Type<TAlternative>() where TAlternative : class |
| 48 | + { |
| 49 | + this._Type = typeof(TAlternative); |
| 50 | + return (TDescriptor)this; |
| 51 | + } |
| 52 | + |
| 53 | + public TDescriptor Type(string type) |
| 54 | + { |
| 55 | + this._Type = type; |
| 56 | + return (TDescriptor)this; |
| 57 | + } |
| 58 | + |
| 59 | + public TDescriptor Type(Type type) |
| 60 | + { |
| 61 | + this._Type = type; |
| 62 | + return (TDescriptor)this; |
| 63 | + } |
| 64 | + |
| 65 | + internal virtual ElasticsearchPathInfo<TParameters> ToPathInfo(IConnectionSettingsValues settings, TParameters queryString) |
| 66 | + { |
| 67 | + var inferrer = new ElasticInferrer(settings); |
| 68 | + if (this._Index == null) |
| 69 | + throw new DslException("Index() not specified"); |
| 70 | + if (this._Type == null) |
| 71 | + throw new DslException("Type() not specified"); |
| 72 | + |
| 73 | + var index = inferrer.IndexName(this._Index); |
| 74 | + var type = inferrer.TypeName(this._Type); |
| 75 | + var pathInfo = new ElasticsearchPathInfo<TParameters>() |
| 76 | + { |
| 77 | + Index = index, |
| 78 | + Type = type |
| 79 | + }; |
| 80 | + pathInfo.RequestParameters = queryString ?? new TParameters(); |
| 81 | + pathInfo.RequestParameters.RequestConfiguration(r=>this._RequestConfiguration); |
| 82 | + return pathInfo; |
| 83 | + } |
| 84 | + |
| 85 | + } |
| 86 | +} |
0 commit comments