Skip to content

Commit 88bc608

Browse files
committed
added support for Document exists requests fix #499
1 parent 69ab6c6 commit 88bc608

15 files changed

+170
-52
lines changed

src/Elasticsearch.Net/Domain/ElasticsearchResponse.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ public interface IElasticsearchResponse
4040
byte[] ResponseRaw { get; }
4141
}
4242

43-
internal static class ElasticsearchResponse
43+
public static class ElasticsearchResponse
4444
{
45-
46-
public static Task<ElasticsearchResponse<DynamicDictionary>> WrapAsync(Task<ElasticsearchResponse<Dictionary<string, object>>> responseTask)
45+
internal static Task<ElasticsearchResponse<DynamicDictionary>> WrapAsync(Task<ElasticsearchResponse<Dictionary<string, object>>> responseTask)
4746
{
4847
return responseTask
4948
.ContinueWith(t =>
@@ -55,7 +54,7 @@ public static Task<ElasticsearchResponse<DynamicDictionary>> WrapAsync(Task<Elas
5554
});
5655
}
5756

58-
public static ElasticsearchResponse<DynamicDictionary> Wrap(ElasticsearchResponse<Dictionary<string, object>> response)
57+
internal static ElasticsearchResponse<DynamicDictionary> Wrap(ElasticsearchResponse<Dictionary<string, object>> response)
5958
{
6059
return ToDynamicResponse(response);
6160
}

src/Elasticsearch.Net/Domain/RequestParameters.Generated.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,12 +1548,12 @@ public DeleteByQueryRequestParameters Timeout(string timeout)
15481548
///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/docs-get.html
15491549
///</pre>
15501550
///</summary>
1551-
public class ExistsRequestParameters : FluentRequestParameters<ExistsRequestParameters>
1551+
public class DocumentExistsRequestParameters : FluentRequestParameters<DocumentExistsRequestParameters>
15521552
{
15531553

15541554
internal string _parent { get; set; }
15551555
///<summary>The ID of the parent document</summary>
1556-
public ExistsRequestParameters Parent(string parent)
1556+
public DocumentExistsRequestParameters Parent(string parent)
15571557
{
15581558
this._parent = parent;
15591559
this.AddQueryString("parent", this._parent);
@@ -1563,7 +1563,7 @@ public ExistsRequestParameters Parent(string parent)
15631563

15641564
internal string _preference { get; set; }
15651565
///<summary>Specify the node or shard the operation should be performed on (default: random)</summary>
1566-
public ExistsRequestParameters Preference(string preference)
1566+
public DocumentExistsRequestParameters Preference(string preference)
15671567
{
15681568
this._preference = preference;
15691569
this.AddQueryString("preference", this._preference);
@@ -1573,7 +1573,7 @@ public ExistsRequestParameters Preference(string preference)
15731573

15741574
internal bool _realtime { get; set; }
15751575
///<summary>Specify whether to perform the operation in realtime or search mode</summary>
1576-
public ExistsRequestParameters Realtime(bool realtime)
1576+
public DocumentExistsRequestParameters Realtime(bool realtime)
15771577
{
15781578
this._realtime = realtime;
15791579
this.AddQueryString("realtime", this._realtime);
@@ -1583,7 +1583,7 @@ public ExistsRequestParameters Realtime(bool realtime)
15831583

15841584
internal bool _refresh { get; set; }
15851585
///<summary>Refresh the shard containing the document before performing the operation</summary>
1586-
public ExistsRequestParameters Refresh(bool refresh)
1586+
public DocumentExistsRequestParameters Refresh(bool refresh)
15871587
{
15881588
this._refresh = refresh;
15891589
this.AddQueryString("refresh", this._refresh);
@@ -1593,7 +1593,7 @@ public ExistsRequestParameters Refresh(bool refresh)
15931593

15941594
internal string _routing { get; set; }
15951595
///<summary>Specific routing value</summary>
1596-
public ExistsRequestParameters Routing(string routing)
1596+
public DocumentExistsRequestParameters Routing(string routing)
15971597
{
15981598
this._routing = routing;
15991599
this.AddQueryString("routing", this._routing);

src/Elasticsearch.Net/ElasticsearchClient.Generated.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6757,7 +6757,7 @@ public Task<ElasticsearchResponse<DynamicDictionary>> DeleteByQueryAsync(string
67576757
///<para> - If T is of type byte[] deserialization will be shortcircuited</para>
67586758
///<para> - If T is of type VoidResponse the response stream will be ignored completely</para>
67596759
///</returns>
6760-
public ElasticsearchResponse<T> Exists<T>(string index, string type, string id, Func<ExistsRequestParameters, ExistsRequestParameters> requestParameters = null)
6760+
public ElasticsearchResponse<T> Exists<T>(string index, string type, string id, Func<DocumentExistsRequestParameters, DocumentExistsRequestParameters> requestParameters = null)
67616761
{
67626762
index.ThrowIfNullOrEmpty("index");
67636763
type.ThrowIfNullOrEmpty("type");
@@ -6766,7 +6766,7 @@ public ElasticsearchResponse<T> Exists<T>(string index, string type, string id,
67666766
BaseRequestParameters requestParams = null;
67676767
if (requestParameters != null)
67686768
{
6769-
requestParams = requestParameters(new ExistsRequestParameters());
6769+
requestParams = requestParameters(new DocumentExistsRequestParameters());
67706770
ToNameValueCollection(requestParams);
67716771
}
67726772

@@ -6794,7 +6794,7 @@ public ElasticsearchResponse<T> Exists<T>(string index, string type, string id,
67946794
///<para> - If T is of type byte[] deserialization will be shortcircuited</para>
67956795
///<para> - If T is of type VoidResponse the response stream will be ignored completely</para>
67966796
///</returns>
6797-
public Task<ElasticsearchResponse<T>> ExistsAsync<T>(string index, string type, string id, Func<ExistsRequestParameters, ExistsRequestParameters> requestParameters = null)
6797+
public Task<ElasticsearchResponse<T>> ExistsAsync<T>(string index, string type, string id, Func<DocumentExistsRequestParameters, DocumentExistsRequestParameters> requestParameters = null)
67986798
{
67996799
index.ThrowIfNullOrEmpty("index");
68006800
type.ThrowIfNullOrEmpty("type");
@@ -6803,7 +6803,7 @@ public Task<ElasticsearchResponse<T>> ExistsAsync<T>(string index, string type,
68036803
BaseRequestParameters requestParams = null;
68046804
if (requestParameters != null)
68056805
{
6806-
requestParams = requestParameters(new ExistsRequestParameters());
6806+
requestParams = requestParameters(new DocumentExistsRequestParameters());
68076807
ToNameValueCollection(requestParams);
68086808
}
68096809

@@ -6833,7 +6833,7 @@ public Task<ElasticsearchResponse<T>> ExistsAsync<T>(string index, string type,
68336833
///<para> - i.e result.Response.hits.hits[0].property.nested["nested_deeper"]</para>
68346834
///<para> - can be safely dispatched to a nullable type even if intermediate properties do not exist</para>
68356835
///</returns>
6836-
public ElasticsearchResponse<DynamicDictionary> Exists(string index, string type, string id, Func<ExistsRequestParameters, ExistsRequestParameters> requestParameters = null)
6836+
public ElasticsearchResponse<DynamicDictionary> Exists(string index, string type, string id, Func<DocumentExistsRequestParameters, DocumentExistsRequestParameters> requestParameters = null)
68376837
{
68386838
index.ThrowIfNullOrEmpty("index");
68396839
type.ThrowIfNullOrEmpty("type");
@@ -6842,7 +6842,7 @@ public ElasticsearchResponse<DynamicDictionary> Exists(string index, string type
68426842
BaseRequestParameters requestParams = null;
68436843
if (requestParameters != null)
68446844
{
6845-
requestParams = requestParameters(new ExistsRequestParameters());
6845+
requestParams = requestParameters(new DocumentExistsRequestParameters());
68466846
ToNameValueCollection(requestParams);
68476847
}
68486848

@@ -6872,7 +6872,7 @@ public ElasticsearchResponse<DynamicDictionary> Exists(string index, string type
68726872
///<para> - i.e result.Response.hits.hits[0].property.nested["nested_deeper"]</para>
68736873
///<para> - can be safely dispatched to a nullable type even if intermediate properties do not exist</para>
68746874
///</returns>
6875-
public Task<ElasticsearchResponse<DynamicDictionary>> ExistsAsync(string index, string type, string id, Func<ExistsRequestParameters, ExistsRequestParameters> requestParameters = null)
6875+
public Task<ElasticsearchResponse<DynamicDictionary>> ExistsAsync(string index, string type, string id, Func<DocumentExistsRequestParameters, DocumentExistsRequestParameters> requestParameters = null)
68766876
{
68776877
index.ThrowIfNullOrEmpty("index");
68786878
type.ThrowIfNullOrEmpty("type");
@@ -6881,7 +6881,7 @@ public Task<ElasticsearchResponse<DynamicDictionary>> ExistsAsync(string index,
68816881
BaseRequestParameters requestParams = null;
68826882
if (requestParameters != null)
68836883
{
6884-
requestParams = requestParameters(new ExistsRequestParameters());
6884+
requestParams = requestParameters(new DocumentExistsRequestParameters());
68856885
ToNameValueCollection(requestParams);
68866886
}
68876887

src/Elasticsearch.Net/IElasticsearchClient.Generated.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3790,7 +3790,7 @@ public interface IElasticsearchClient
37903790
///<para> - If T is of type VoidResponse the response stream will be ignored completely</para>
37913791
///</returns>
37923792

3793-
ElasticsearchResponse<T> Exists<T>(string index, string type, string id, Func<ExistsRequestParameters, ExistsRequestParameters> requestParameters = null);
3793+
ElasticsearchResponse<T> Exists<T>(string index, string type, string id, Func<DocumentExistsRequestParameters, DocumentExistsRequestParameters> requestParameters = null);
37943794

37953795
///<summary>Represents a HEAD on /{index}/{type}/{id}
37963796
///<para></para>Returns: A task that'll return an ElasticsearchResponse&lt;T&gt; holding the reponse body deserialized as T.
@@ -3810,7 +3810,7 @@ public interface IElasticsearchClient
38103810
///<para> - If T is of type VoidResponse the response stream will be ignored completely</para>
38113811
///</returns>
38123812

3813-
Task<ElasticsearchResponse<T>> ExistsAsync<T>(string index, string type, string id, Func<ExistsRequestParameters, ExistsRequestParameters> requestParameters = null);
3813+
Task<ElasticsearchResponse<T>> ExistsAsync<T>(string index, string type, string id, Func<DocumentExistsRequestParameters, DocumentExistsRequestParameters> requestParameters = null);
38143814

38153815
///<summary>Represents a HEAD on /{index}/{type}/{id}
38163816
///<para></para>Returns: ElasticsearchResponse&lt;T&gt; holding the response body deserialized as DynamicDictionary
@@ -3832,7 +3832,7 @@ public interface IElasticsearchClient
38323832
///<para> - can be safely dispatched to a nullable type even if intermediate properties do not exist</para>
38333833
///</returns>
38343834

3835-
ElasticsearchResponse<DynamicDictionary> Exists(string index, string type, string id, Func<ExistsRequestParameters, ExistsRequestParameters> requestParameters = null);
3835+
ElasticsearchResponse<DynamicDictionary> Exists(string index, string type, string id, Func<DocumentExistsRequestParameters, DocumentExistsRequestParameters> requestParameters = null);
38363836

38373837
///<summary>Represents a HEAD on /{index}/{type}/{id}
38383838
///<para></para>Returns: Task that'll return an ElasticsearchResponse&lt;T$gt; holding the response body deserialized as DynamicDictionary
@@ -3854,7 +3854,7 @@ public interface IElasticsearchClient
38543854
///<para> - can be safely dispatched to a nullable type even if intermediate properties do not exist</para>
38553855
///</returns>
38563856

3857-
Task<ElasticsearchResponse<DynamicDictionary>> ExistsAsync(string index, string type, string id, Func<ExistsRequestParameters, ExistsRequestParameters> requestParameters = null);
3857+
Task<ElasticsearchResponse<DynamicDictionary>> ExistsAsync(string index, string type, string id, Func<DocumentExistsRequestParameters, DocumentExistsRequestParameters> requestParameters = null);
38583858

38593859
///<summary>Represents a GET on /{index}/{type}/{id}/_explain
38603860
///<para></para>Returns: ElasticsearchResponse&lt;T&gt; holding the reponse body deserialized as T.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using Elasticsearch.Net;
7+
using Newtonsoft.Json;
8+
using Newtonsoft.Json.Converters;
9+
using Nest.Resolvers.Converters;
10+
using System.Linq.Expressions;
11+
using Nest.Resolvers;
12+
13+
namespace Nest
14+
{
15+
[DescriptorFor("Exists")]
16+
public partial class IndexDescriptor<T> : DocumentPathDescriptorBase<IndexDescriptor<T>, T, IndexRequestParameters>
17+
, IPathInfo<IndexRequestParameters>
18+
where T : class
19+
{
20+
ElasticsearchPathInfo<IndexRequestParameters> IPathInfo<IndexRequestParameters>.ToPathInfo(IConnectionSettingsValues settings)
21+
{
22+
var pathInfo = base.ToPathInfo<IndexRequestParameters>(settings, this._QueryString);
23+
pathInfo.HttpMethod = this._Id.IsNullOrEmpty() ? PathInfoHttpMethod.POST : PathInfoHttpMethod.PUT;
24+
return pathInfo;
25+
}
26+
}
27+
}

src/Nest/DSL/IndexDescriptor.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212

1313
namespace Nest
1414
{
15-
[DescriptorFor("Index")]
16-
public partial class IndexDescriptor<T> : DocumentPathDescriptorBase<IndexDescriptor<T>, T, IndexRequestParameters>
17-
, IPathInfo<IndexRequestParameters>
15+
[DescriptorFor("Exists")]
16+
public partial class DocumentExistsDescriptor<T> : DocumentPathDescriptorBase<DocumentExistsDescriptor<T>, T, DocumentExistsRequestParameters>
17+
, IPathInfo<DocumentExistsRequestParameters>
1818
where T : class
1919
{
20-
ElasticsearchPathInfo<IndexRequestParameters> IPathInfo<IndexRequestParameters>.ToPathInfo(IConnectionSettingsValues settings)
20+
ElasticsearchPathInfo<DocumentExistsRequestParameters> IPathInfo<DocumentExistsRequestParameters>.ToPathInfo(IConnectionSettingsValues settings)
2121
{
22-
var pathInfo = base.ToPathInfo<IndexRequestParameters>(settings, this._QueryString);
23-
pathInfo.HttpMethod = this._Id.IsNullOrEmpty() ? PathInfoHttpMethod.POST : PathInfoHttpMethod.PUT;
22+
var pathInfo = base.ToPathInfo<DocumentExistsRequestParameters>(settings, this._QueryString);
23+
pathInfo.HttpMethod = PathInfoHttpMethod.HEAD;
2424
return pathInfo;
2525
}
2626
}

src/Nest/DSL/_Descriptors.generated.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,45 +1365,45 @@ public DeleteByQueryDescriptor<T> Timeout(string timeout)
13651365
///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/docs-get.html
13661366
///</pre>
13671367
///</summary>
1368-
public partial class ExistsDescriptor
1368+
public partial class DocumentExistsDescriptor<T>
13691369
{
1370-
internal ExistsRequestParameters _QueryString = new ExistsRequestParameters();
1370+
internal DocumentExistsRequestParameters _QueryString = new DocumentExistsRequestParameters();
13711371

13721372

13731373
///<summary>The ID of the parent document</summary>
1374-
public ExistsDescriptor Parent(string parent)
1374+
public DocumentExistsDescriptor<T> Parent(string parent)
13751375
{
13761376
this._QueryString.Parent(parent);
13771377
return this;
13781378
}
13791379

13801380

13811381
///<summary>Specify the node or shard the operation should be performed on (default: random)</summary>
1382-
public ExistsDescriptor Preference(string preference)
1382+
public DocumentExistsDescriptor<T> Preference(string preference)
13831383
{
13841384
this._QueryString.Preference(preference);
13851385
return this;
13861386
}
13871387

13881388

13891389
///<summary>Specify whether to perform the operation in realtime or search mode</summary>
1390-
public ExistsDescriptor Realtime(bool realtime = true)
1390+
public DocumentExistsDescriptor<T> Realtime(bool realtime = true)
13911391
{
13921392
this._QueryString.Realtime(realtime);
13931393
return this;
13941394
}
13951395

13961396

13971397
///<summary>Refresh the shard containing the document before performing the operation</summary>
1398-
public ExistsDescriptor Refresh(bool refresh = true)
1398+
public DocumentExistsDescriptor<T> Refresh(bool refresh = true)
13991399
{
14001400
this._QueryString.Refresh(refresh);
14011401
return this;
14021402
}
14031403

14041404

14051405
///<summary>Specific routing value</summary>
1406-
public ExistsDescriptor Routing(string routing)
1406+
public DocumentExistsDescriptor<T> Routing(string routing)
14071407
{
14081408
this._QueryString.Routing(routing);
14091409
return this;

src/Nest/Domain/Responses/IndexExistsResponse.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,25 @@
44

55
namespace Nest
66
{
7-
public interface IIndexExistsResponse : IResponse
7+
public interface IExistsResponse : IResponse
88
{
99
bool Exists { get; }
1010
}
1111

1212
[JsonObject]
13-
public class IndexExistsResponse : BaseResponse, IIndexExistsResponse
13+
public class ExistsResponse : BaseResponse, IExistsResponse
1414
{
15-
internal IndexExistsResponse(IElasticsearchResponse connectionStatus)
15+
internal ExistsResponse(IElasticsearchResponse connectionStatus)
1616
{
1717
this.ConnectionStatus = connectionStatus;
1818
this.IsValid =connectionStatus.Success || connectionStatus.HttpStatusCode == 404;
1919
this.Exists = connectionStatus.Success & connectionStatus.HttpStatusCode == 200;
2020
}
21+
public ExistsResponse()
22+
{
23+
this.IsValid = false;
24+
this.Exists = false;
25+
}
2126

2227
public bool Exists { get; internal set; }
2328
}

src/Nest/ElasticClient-Exists.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Elasticsearch.Net;
4+
5+
namespace Nest
6+
{
7+
public partial class ElasticClient
8+
{
9+
/// <inheritdoc />
10+
public IExistsResponse DocumentExists<T>(Func<DocumentExistsDescriptor<T>, DocumentExistsDescriptor<T>> existsSelector)
11+
where T : class
12+
{
13+
return this.Dispatch<DocumentExistsDescriptor<T>, DocumentExistsRequestParameters, ExistsResponse>(
14+
existsSelector,
15+
(p, d) => ToExistsResponse(this.RawDispatch.ExistsDispatch<VoidResponse>(p))
16+
, allow404: true
17+
18+
);
19+
}
20+
21+
/// <inheritdoc />
22+
public Task<IExistsResponse> DocumentExistsAsync<T>(Func<DocumentExistsDescriptor<T>, DocumentExistsDescriptor<T>> existsSelector)
23+
where T : class
24+
{
25+
return this.DispatchAsync<DocumentExistsDescriptor<T>, DocumentExistsRequestParameters, ExistsResponse, IExistsResponse>(
26+
existsSelector,
27+
(p, d) => this.RawDispatch.ExistsDispatchAsync<ExistsResponse>(p)
28+
, allow404: true
29+
);
30+
}
31+
32+
private ElasticsearchResponse<ExistsResponse> ToExistsResponse(ElasticsearchResponse<VoidResponse> existsDispatch)
33+
{
34+
return ElasticsearchResponse.CloneFrom<ExistsResponse>(existsDispatch, new ExistsResponse(existsDispatch));
35+
}
36+
}
37+
}

src/Nest/ElasticClient-IndexExists.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,37 @@
55

66
namespace Nest
77
{
8-
using IndexExistConverter = Func<IElasticsearchResponse, Stream, IndexExistsResponse>;
8+
using IndexExistConverter = Func<IElasticsearchResponse, Stream, ExistsResponse>;
99

1010
public partial class ElasticClient
1111
{
1212
/// <inheritdoc />
13-
public IIndexExistsResponse IndexExists(Func<IndexExistsDescriptor, IndexExistsDescriptor> selector)
13+
public IExistsResponse IndexExists(Func<IndexExistsDescriptor, IndexExistsDescriptor> selector)
1414
{
15-
return this.Dispatch<IndexExistsDescriptor, IndexExistsRequestParameters, IndexExistsResponse>(
15+
return this.Dispatch<IndexExistsDescriptor, IndexExistsRequestParameters, ExistsResponse>(
1616
selector,
17-
(p, d) => this.RawDispatch.IndicesExistsDispatch<IndexExistsResponse>(
17+
(p, d) => this.RawDispatch.IndicesExistsDispatch<ExistsResponse>(
1818
p.DeserializationState(new IndexExistConverter(DeserializeExistsResponse))
1919
),
2020
allow404: true
2121
);
2222
}
2323

2424
/// <inheritdoc />
25-
public Task<IIndexExistsResponse> IndexExistsAsync(Func<IndexExistsDescriptor, IndexExistsDescriptor> selector)
25+
public Task<IExistsResponse> IndexExistsAsync(Func<IndexExistsDescriptor, IndexExistsDescriptor> selector)
2626
{
27-
return this.DispatchAsync<IndexExistsDescriptor, IndexExistsRequestParameters, IndexExistsResponse, IIndexExistsResponse>(
27+
return this.DispatchAsync<IndexExistsDescriptor, IndexExistsRequestParameters, ExistsResponse, IExistsResponse>(
2828
selector,
29-
(p, d) => this.RawDispatch.IndicesExistsDispatchAsync<IndexExistsResponse>(
29+
(p, d) => this.RawDispatch.IndicesExistsDispatchAsync<ExistsResponse>(
3030
p.DeserializationState(new IndexExistConverter(DeserializeExistsResponse))
3131
),
3232
allow404: true
3333
);
3434
}
3535

36-
private IndexExistsResponse DeserializeExistsResponse(IElasticsearchResponse response, Stream stream)
36+
private ExistsResponse DeserializeExistsResponse(IElasticsearchResponse response, Stream stream)
3737
{
38-
return new IndexExistsResponse(response);
38+
return new ExistsResponse(response);
3939
}
4040
}
4141
}

0 commit comments

Comments
 (0)