/src/Nest/ElasticClient-DeleteById.cs

https://github.com/wryczko/NEST · C# · 179 lines · 103 code · 20 blank · 56 comment · 0 complexity · 0a264bd00472f35ffbc9bb64508fa1cf MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. namespace Nest
  5. {
  6. public partial class ElasticClient
  7. {
  8. /// <summary>
  9. /// Synchronously deletes a document by id in the default index and the inferred typename for T
  10. /// </summary>
  11. public IDeleteResponse DeleteById<T>(int id) where T : class
  12. {
  13. return this.DeleteById<T>(id.ToString());
  14. }
  15. /// <summary>
  16. /// Synchronously deletes a document by id in the default index and the inferred typename for T
  17. /// </summary>
  18. public IDeleteResponse DeleteById<T>(string id) where T : class
  19. {
  20. var index = this.IndexNameResolver.GetIndexForType<T>();
  21. index.ThrowIfNullOrEmpty("Cannot infer default index for current connection.");
  22. var typeName = this.TypeNameResolver.GetTypeNameFor<T>();
  23. var path = this.PathResolver.CreateIndexTypeIdPath(index, typeName, id);
  24. return this._deleteToPath(path);
  25. }
  26. /// <summary>
  27. /// Synchronously deletes a document by id in the specified index and type
  28. /// </summary>
  29. public IDeleteResponse DeleteById(string index, string type, string id)
  30. {
  31. var path = this.PathResolver.CreateIndexTypeIdPath(index, type, id);
  32. return this._deleteToPath(path);
  33. }
  34. /// <summary>
  35. /// Synchronously deletes a document by id in the specified index and type
  36. /// </summary>
  37. public IDeleteResponse DeleteById(string index, string type, int id)
  38. {
  39. var path = this.PathResolver.CreateIndexTypeIdPath(index, type, id.ToString());
  40. return this._deleteToPath(path);
  41. }
  42. /// <summary>
  43. /// Synchronously deletes a document by id in the default index and the inferred typename for T
  44. /// </summary>
  45. /// <param name="deleteParameters">Allows you to pass in additional delete parameters such as version and routing</param>
  46. public IDeleteResponse DeleteById<T>(int id, DeleteParameters deleteParameters) where T : class
  47. {
  48. return this.DeleteById<T>(id.ToString(), deleteParameters);
  49. }
  50. /// <summary>
  51. /// Synchronously deletes a document by id in the default index and the inferred typename for T
  52. /// </summary>
  53. /// <param name="deleteParameters">Allows you to pass in additional delete parameters such as version and routing</param>
  54. public IDeleteResponse DeleteById<T>(string id, DeleteParameters deleteParameters) where T : class
  55. {
  56. var index = this.IndexNameResolver.GetIndexForType<T>();
  57. index.ThrowIfNullOrEmpty("Cannot infer default index for current connection.");
  58. var typeName = this.TypeNameResolver.GetTypeNameFor<T>();
  59. var path = this.PathResolver.CreateIndexTypeIdPath(index, typeName, id);
  60. path = this.PathResolver.AppendParametersToPath(path, deleteParameters);
  61. return this._deleteToPath(path);
  62. }
  63. /// <summary>
  64. /// Synchronously deletes a document by id in the specified index and type
  65. /// </summary>
  66. /// <param name="deleteParameters">Allows you to pass in additional delete parameters such as version and routing</param>
  67. public IDeleteResponse DeleteById(string index, string type, string id, DeleteParameters deleteParameters)
  68. {
  69. var path = this.PathResolver.CreateIndexTypeIdPath(index, type, id);
  70. path = this.PathResolver.AppendParametersToPath(path, deleteParameters);
  71. return this._deleteToPath(path);
  72. }
  73. /// <summary>
  74. /// Synchronously deletes a document by id in the specified index and type
  75. /// </summary>
  76. /// <param name="deleteParameters">Allows you to pass in additional delete parameters such as version and routing</param>
  77. public IDeleteResponse DeleteById(string index, string type, int id, DeleteParameters deleteParameters)
  78. {
  79. var path = this.PathResolver.CreateIndexTypeIdPath(index, type, id.ToString());
  80. path = this.PathResolver.AppendParametersToPath(path, deleteParameters);
  81. return this._deleteToPath(path);
  82. }
  83. /// <summary>
  84. /// Asynchronously deletes a document by id in the default index and the inferred typename for T
  85. /// </summary>
  86. public Task<IDeleteResponse> DeleteByIdAsync<T>(int id) where T : class
  87. {
  88. return this.DeleteByIdAsync<T>(id.ToString());
  89. }
  90. /// <summary>
  91. /// Asynchronously deletes a document by id in the default index and the inferred typename for T
  92. /// </summary>
  93. public Task<IDeleteResponse> DeleteByIdAsync<T>(string id) where T : class
  94. {
  95. var index = this.IndexNameResolver.GetIndexForType<T>();
  96. index.ThrowIfNullOrEmpty("Cannot infer default index for current connection.");
  97. var typeName = this.TypeNameResolver.GetTypeNameFor<T>();
  98. var path = this.PathResolver.CreateIndexTypeIdPath(index, typeName, id);
  99. return this._deleteToPathAsync(path);
  100. }
  101. /// <summary>
  102. /// Asynchronously deletes a document by id in the specified index and type
  103. /// </summary>
  104. public Task<IDeleteResponse> DeleteByIdAsync(string index, string type, string id)
  105. {
  106. var path = this.PathResolver.CreateIndexTypeIdPath(index, type, id);
  107. return this._deleteToPathAsync(path);
  108. }
  109. /// <summary>
  110. /// Asynchronously deletes a document by id in the specified index and type
  111. /// </summary>
  112. public Task<IDeleteResponse> DeleteByIdAsync(string index, string type, int id)
  113. {
  114. var path = this.PathResolver.CreateIndexTypeIdPath(index, type, id.ToString());
  115. return this._deleteToPathAsync(path);
  116. }
  117. /// <summary>
  118. /// Asynchronously deletes a document by id in the default index and the inferred typename for T
  119. /// </summary>
  120. /// <param name="deleteParameters">Allows you to pass in additional delete parameters such as version and routing</param>
  121. public Task<IDeleteResponse> DeleteByIdAsync<T>(int id, DeleteParameters deleteParameters) where T : class
  122. {
  123. return this.DeleteByIdAsync<T>(id.ToString(), deleteParameters);
  124. }
  125. /// <summary>
  126. /// Asynchronously deletes a document by id in the default index and the inferred typename for T
  127. /// </summary>
  128. /// <param name="deleteParameters">Allows you to pass in additional delete parameters such as version and routing</param>
  129. public Task<IDeleteResponse> DeleteByIdAsync<T>(string id, DeleteParameters deleteParameters) where T : class
  130. {
  131. var index = this.IndexNameResolver.GetIndexForType<T>();
  132. index.ThrowIfNullOrEmpty("Cannot infer default index for current connection.");
  133. var typeName = this.TypeNameResolver.GetTypeNameFor<T>();
  134. var path = this.PathResolver.CreateIndexTypeIdPath(index, typeName, id);
  135. path = this.PathResolver.AppendParametersToPath(path, deleteParameters);
  136. return this._deleteToPathAsync(path);
  137. }
  138. /// <summary>
  139. /// Asynchronously deletes a document by id in the specified index and type
  140. /// </summary>
  141. /// <param name="deleteParameters">Allows you to pass in additional delete parameters such as version and routing</param>
  142. public Task<IDeleteResponse> DeleteByIdAsync(string index, string type, string id, DeleteParameters deleteParameters)
  143. {
  144. var path = this.PathResolver.CreateIndexTypeIdPath(index, type, id);
  145. path = this.PathResolver.AppendParametersToPath(path, deleteParameters);
  146. return this._deleteToPathAsync(path);
  147. }
  148. /// <summary>
  149. /// Asynchronously deletes a document by id in the specified index and type
  150. /// </summary>
  151. /// <param name="deleteParameters">Allows you to pass in additional delete parameters such as version and routing</param>
  152. public Task<IDeleteResponse> DeleteByIdAsync(string index, string type, int id, DeleteParameters deleteParameters)
  153. {
  154. var path = this.PathResolver.CreateIndexTypeIdPath(index, type, id.ToString());
  155. path = this.PathResolver.AppendParametersToPath(path, deleteParameters);
  156. return this._deleteToPathAsync(path);
  157. }
  158. }
  159. }