diff --git a/src/Nest/DSL/CountDescriptor.cs b/src/Nest/DSL/CountDescriptor.cs index 4a44abc0d71..e33ddf3a294 100644 --- a/src/Nest/DSL/CountDescriptor.cs +++ b/src/Nest/DSL/CountDescriptor.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Elasticsearch.Net; using Newtonsoft.Json; @@ -28,6 +29,12 @@ public static void Update(ElasticsearchPathInfo pathInfo public partial class CountRequest : QueryPathBase, ICountRequest { + public CountRequest() {} + + public CountRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { } + + public CountRequest(IEnumerable indices, IEnumerable types = null) : base(indices, types) { } + public IQueryContainer Query { get; set; } protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo pathInfo) @@ -39,6 +46,12 @@ protected override void UpdatePathInfo(IConnectionSettingsValues settings, Elast public partial class CountRequest : QueryPathBase, ICountRequest where T : class { + public CountRequest() {} + + public CountRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { } + + public CountRequest(IEnumerable indices, IEnumerable types = null) : base(indices, types) { } + public IQueryContainer Query { get; set; } protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo pathInfo) diff --git a/src/Nest/DSL/DeleteByQueryDescriptor.cs b/src/Nest/DSL/DeleteByQueryDescriptor.cs index 51f62060df1..9beb581ae66 100644 --- a/src/Nest/DSL/DeleteByQueryDescriptor.cs +++ b/src/Nest/DSL/DeleteByQueryDescriptor.cs @@ -33,31 +33,14 @@ public static void Update(ElasticsearchPathInfo public partial class DeleteByQueryRequest : QueryPathBase, IDeleteByQueryRequest { - public IQueryContainer Query { get; set; } + public DeleteByQueryRequest() {} - /// - /// Sents a delete query to _all indices - /// - public DeleteByQueryRequest() - { - this.AllIndices = true; - this.AllTypes = true; - } - - public DeleteByQueryRequest(IndexNameMarker index, TypeNameMarker type = null) - { - this.Indices = new [] { index }; - if (type != null) - this.Types = new[] { type }; - else this.AllTypes = true; - } + public DeleteByQueryRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { } + + public DeleteByQueryRequest(IEnumerable indices, IEnumerable types = null) : base(indices, types) { } + + public IQueryContainer Query { get; set; } - public DeleteByQueryRequest(IEnumerable indices, IEnumerable types = null) - { - this.Indices = indices; - this.AllTypes = !types.HasAny(); - this.Types = types; - } protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo pathInfo) { @@ -68,6 +51,12 @@ protected override void UpdatePathInfo(IConnectionSettingsValues settings, Elast public partial class DeleteByQueryRequest : QueryPathBase, IDeleteByQueryRequest where T : class { + public DeleteByQueryRequest() {} + + public DeleteByQueryRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { } + + public DeleteByQueryRequest(IEnumerable indices, IEnumerable types = null) : base(indices, types) { } + public IQueryContainer Query { get; set; } protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo pathInfo) diff --git a/src/Nest/DSL/Paths/QueryPathDescriptor.cs b/src/Nest/DSL/Paths/QueryPathDescriptor.cs index f30247488ca..acdefea8f0c 100644 --- a/src/Nest/DSL/Paths/QueryPathDescriptor.cs +++ b/src/Nest/DSL/Paths/QueryPathDescriptor.cs @@ -77,6 +77,26 @@ public static void SetRouteParameters( public abstract class QueryPathBase : BasePathRequest, IQueryPath where TParameters : IRequestParameters, new() { + protected QueryPathBase() + { + this.AllTypes = true; + } + + protected QueryPathBase(IndexNameMarker index, TypeNameMarker type = null) + { + this.Indices = new [] { index }; + if (type != null) + this.Types = new[] { type }; + else this.AllTypes = true; + } + + protected QueryPathBase(IEnumerable indices, IEnumerable types = null) + { + this.Indices = indices; + this.AllTypes = !types.HasAny(); + this.Types = types; + } + protected override void SetRouteParameters(IConnectionSettingsValues settings, ElasticsearchPathInfo pathInfo) { @@ -94,6 +114,24 @@ public abstract class QueryPathBase : QueryPathBase where TParameters : IRequestParameters, new() where T : class { + protected QueryPathBase() + { + this.AllIndices = false; + this.AllTypes = false; + } + + protected QueryPathBase(IndexNameMarker index, TypeNameMarker type = null) + { + this.Indices = new [] { index }; + if (type != null) + this.Types = new[] { type }; + } + + protected QueryPathBase(IEnumerable indices, IEnumerable types = null) + { + this.Indices = indices; + this.Types = types; + } protected override void SetRouteParameters(IConnectionSettingsValues settings, ElasticsearchPathInfo pathInfo) { diff --git a/src/Nest/DSL/SearchDescriptor.cs b/src/Nest/DSL/SearchDescriptor.cs index eea7d97b908..554acf604a2 100644 --- a/src/Nest/DSL/SearchDescriptor.cs +++ b/src/Nest/DSL/SearchDescriptor.cs @@ -127,6 +127,12 @@ public static void Update(IConnectionSettingsValues settings, ElasticsearchPathI public partial class SearchRequest : QueryPathBase, ISearchRequest { + public SearchRequest() {} + + public SearchRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { } + + public SearchRequest(IEnumerable indices, IEnumerable types = null) : base(indices, types) { } + private Type _clrType { get; set; } Type ISearchRequest.ClrType { get { return _clrType; } } @@ -186,6 +192,12 @@ protected override void UpdatePathInfo(IConnectionSettingsValues settings, Elast public partial class SearchRequest : QueryPathBase, ISearchRequest where T : class { + public SearchRequest() {} + + public SearchRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { } + + public SearchRequest(IEnumerable indices, IEnumerable types = null) : base(indices, types) { } + protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo pathInfo) { SearchPathInfo.Update(settings,pathInfo, this); diff --git a/src/Nest/DSL/SearchShardsDescriptor.cs b/src/Nest/DSL/SearchShardsDescriptor.cs index 5e9462bfd7f..ddc470da8c5 100644 --- a/src/Nest/DSL/SearchShardsDescriptor.cs +++ b/src/Nest/DSL/SearchShardsDescriptor.cs @@ -27,6 +27,12 @@ public static void Update(IConnectionSettingsValues settings, ElasticsearchPathI public partial class SearchShardsRequest : QueryPathBase, ISearchShardsRequest { + public SearchShardsRequest() {} + + public SearchShardsRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { } + + public SearchShardsRequest(IEnumerable indices, IEnumerable types = null) : base(indices, types) { } + protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo pathInfo) { SearchShardsPathInfo.Update(settings, pathInfo, this); @@ -36,6 +42,12 @@ protected override void UpdatePathInfo(IConnectionSettingsValues settings, Elast public partial class SearchShardsRequest : QueryPathBase, ISearchShardsRequest where T : class { + public SearchShardsRequest() {} + + public SearchShardsRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { } + + public SearchShardsRequest(IEnumerable indices, IEnumerable types = null) : base(indices, types) { } + protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo pathInfo) { SearchShardsPathInfo.Update(settings,pathInfo, this); diff --git a/src/Nest/DSL/ValidateQueryDescriptor.cs b/src/Nest/DSL/ValidateQueryDescriptor.cs index c026e96dbab..c80a99fbd3e 100644 --- a/src/Nest/DSL/ValidateQueryDescriptor.cs +++ b/src/Nest/DSL/ValidateQueryDescriptor.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Elasticsearch.Net; using Newtonsoft.Json; @@ -29,7 +30,13 @@ public static void Update(ElasticsearchPathInfo public partial class ValidateQueryRequest : QueryPathBase, IValidateQueryRequest { - public IQueryContainer Query { get; set; } + public ValidateQueryRequest() {} + + public ValidateQueryRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { } + + public ValidateQueryRequest(IEnumerable indices, IEnumerable types = null) : base(indices, types) { } + + public IQueryContainer Query { get; set; } protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo pathInfo) { @@ -40,7 +47,14 @@ protected override void UpdatePathInfo(IConnectionSettingsValues settings, Elast public partial class ValidateQueryRequest : QueryPathBase, IValidateQueryRequest where T : class { - public IQueryContainer Query { get; set; } + + public ValidateQueryRequest() {} + + public ValidateQueryRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { } + + public ValidateQueryRequest(IEnumerable indices, IEnumerable types = null) : base(indices, types) { } + + public IQueryContainer Query { get; set; } protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo pathInfo) { diff --git a/src/Nest/ExposedInternals/ElasticInferrer.cs b/src/Nest/ExposedInternals/ElasticInferrer.cs index ad215de40f9..b5dde5537cc 100644 --- a/src/Nest/ExposedInternals/ElasticInferrer.cs +++ b/src/Nest/ExposedInternals/ElasticInferrer.cs @@ -39,7 +39,8 @@ public string DefaultIndex { get { - return (this._connectionSettings == null) ? string.Empty : this._connectionSettings.DefaultIndex; + var index = (this._connectionSettings == null) ? string.Empty : this._connectionSettings.DefaultIndex; + return index.IsNullOrEmpty() ? "_all" : index; } } diff --git a/src/Tests/Nest.Tests.Integration/Nest.Tests.Integration.csproj b/src/Tests/Nest.Tests.Integration/Nest.Tests.Integration.csproj index 87a8f370edc..dbf57c774c4 100644 --- a/src/Tests/Nest.Tests.Integration/Nest.Tests.Integration.csproj +++ b/src/Tests/Nest.Tests.Integration/Nest.Tests.Integration.csproj @@ -89,6 +89,7 @@ LinkedExtensions\TypeExtensions.cs + diff --git a/src/Tests/Nest.Tests.Unit/ObjectInitializer/DeleteByQuery/DeleteByQueryRequestTests.cs b/src/Tests/Nest.Tests.Unit/ObjectInitializer/DeleteByQuery/DeleteByQueryRequestTests.cs index e61d8a4160a..419418dfe37 100644 --- a/src/Tests/Nest.Tests.Unit/ObjectInitializer/DeleteByQuery/DeleteByQueryRequestTests.cs +++ b/src/Tests/Nest.Tests.Unit/ObjectInitializer/DeleteByQuery/DeleteByQueryRequestTests.cs @@ -30,6 +30,7 @@ public DeleteByQueryRequestTests() var request = new DeleteByQueryRequest() { + AllIndices = true, AllowNoIndices = true, ExpandWildcards = ExpandWildcards.Closed, Query = query, diff --git a/src/Tests/Nest.Tests.Unit/ObjectInitializer/DeleteByQuery/DeleteByQueryRequestUrlTests.cs b/src/Tests/Nest.Tests.Unit/ObjectInitializer/DeleteByQuery/DeleteByQueryRequestUrlTests.cs index 6cc0bf59994..86545d85fad 100644 --- a/src/Tests/Nest.Tests.Unit/ObjectInitializer/DeleteByQuery/DeleteByQueryRequestUrlTests.cs +++ b/src/Tests/Nest.Tests.Unit/ObjectInitializer/DeleteByQuery/DeleteByQueryRequestUrlTests.cs @@ -17,7 +17,7 @@ public void Untyped_Defaults() var status = this._client.DeleteByQuery(new DeleteByQueryRequest()) .ConnectionStatus; - status.RequestUrl.Should().EndWith("/_all/_query"); + status.RequestUrl.Should().EndWith("/nest_test_data/_query"); status.RequestMethod.Should().Be("DELETE"); }