Skip to content

Fix missing _all when types are specified but no default index is set #1162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Nest/DSL/Paths/QueryPathDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public static void SetRouteParameters<TParameters, T>(
//start out with defaults
var inferrer = new ElasticInferrer(settings);


var index = inferrer.IndexName<T>();
var type = inferrer.TypeName<T>();
pathInfo.Index = index;
Expand All @@ -66,11 +65,11 @@ public static void SetRouteParameters<TParameters, T>(

if (path.Indices.HasAny())
pathInfo.Index = inferrer.IndexNames(path.Indices);
else if (path.AllIndices.GetValueOrDefault(false) && !pathInfo.Type.IsNullOrEmpty())
pathInfo.Index = "_all";
else
pathInfo.Index = path.AllIndices.GetValueOrDefault(false) ? null : inferrer.IndexName<T>();

if (pathInfo.Index.IsNullOrEmpty() && !pathInfo.Type.IsNullOrEmpty())
pathInfo.Index = "_all";
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@
<Compile Include="Search\Query\Singles\SpanMultiTermQueryJson.cs" />
<Compile Include="Search\Query\Singles\TemplateQueryJson.cs" />
<Compile Include="Search\Query\Singles\Term\TermToStringJson.cs" />
<Compile Include="Search\SearchUrlTests.cs" />
<Compile Include="Search\Rescoring\RescoreTests.cs" />
<Compile Include="Search\Facets\DateHistogramFacetJson.cs" />
<Compile Include="Search\Facets\FacetJson.cs" />
Expand Down
331 changes: 331 additions & 0 deletions src/Tests/Nest.Tests.Unit/Search/SearchUrlTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,331 @@
using FluentAssertions;
using Elasticsearch.Net.Connection;
using Nest.Tests.MockData.Domain;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;

namespace Nest.Tests.Unit.Search
{
[TestFixture]
public class SearchUrlTests
{
private void TestUrl(string expected, SearchDescriptor<ElasticsearchProject> descriptor, ConnectionSettings settings = null)
{
var client = new ElasticClient(settings, new InMemoryConnection());
var response = client.Search<ElasticsearchProject>(descriptor);
var uri = new Uri(response.ConnectionStatus.RequestUrl);
var actual = WebUtility.UrlDecode(uri.AbsolutePath);
actual.Should().Be(expected);
}

[Test]
public void AllIndices_AllTypes_Test()
{
TestUrl(
expected: "/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
.AllIndices()
.AllTypes()
);
}

[Test]
public void AllIndices_ExplicitType_Test()
{
TestUrl(
expected: "/_all/type1/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
.AllIndices()
.Type("type1")
);
}

[Test]
public void AllIndices_MultipleExplicitTypes_Test()
{
TestUrl(
expected: "/_all/type1,type2/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
.AllIndices()
.Types("type1", "type2")
);
}

[Test]
public void AllIndices_InferredType_Test()
{
TestUrl(
expected: "/_all/elasticsearchprojects/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
.AllIndices()
);
}

[Test]
public void AllIndices_MappedType_Test()
{
TestUrl(
expected: "/_all/type1/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
.AllIndices(),
settings: new ConnectionSettings()
.MapDefaultTypeNames(m => m
.Add(typeof(ElasticsearchProject), "type1")
)
);
}

[Test]
public void DefaultIndex_AllIndices_AllTypes_Test()
{
TestUrl(
expected: "/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
.AllIndices()
.AllTypes(),
settings: new ConnectionSettings()
.SetDefaultIndex("defaultindex")
);
}

[Test]
public void DefaultIndex_AllTypes_Test()
{
TestUrl(
expected: "/defaultindex/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
.AllTypes(),
settings: new ConnectionSettings()
.SetDefaultIndex("defaultindex")
);
}

[Test]
public void DefaultIndex_ExplicitType_Test()
{
TestUrl(
expected: "/defaultindex/type1/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
.Type("type1"),
settings: new ConnectionSettings()
.SetDefaultIndex("defaultindex")
);
}

[Test]
public void DefaultIndex_MultipleExplicitTypes_Test()
{
TestUrl(
expected: "/defaultindex/type1,type2/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
.Types("type1", "type2"),
settings: new ConnectionSettings()
.SetDefaultIndex("defaultindex")
);
}

[Test]
public void DefaultIndex_InferredType_Test()
{
TestUrl(
expected: "/defaultindex/elasticsearchprojects/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>(),
settings: new ConnectionSettings()
.SetDefaultIndex("defaultindex")
);
}

[Test]
public void DefaultIndex_MappedType_Test()
{
TestUrl(
expected: "/defaultindex/type1/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>(),
settings: new ConnectionSettings()
.SetDefaultIndex("defaultindex")
.MapDefaultTypeNames(m => m
.Add(typeof(ElasticsearchProject), "type1")
)
);
}

[Test]
public void No_DefaultIndex_AllIndices_AllTypes_Test()
{
TestUrl(
expected: "/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
.AllIndices()
.AllTypes()
);
}

[Test]
public void No_DefaultIndex_AllTypes_Test()
{
TestUrl(
expected: "/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
.AllTypes()
);
}

[Test]
public void No_DefaultIndex_ExplicitType_Test()
{
TestUrl(
expected: "/_all/type1/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
.Type("type1")
);
}

[Test]
public void No_DefaultIndex_MultipleExplicitTypes_Test()
{
TestUrl(
expected: "/_all/type1,type2/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
.Types("type1", "type2")
);
}

[Test]
public void No_DefaultIndex_InferredType_Test()
{
TestUrl(
expected: "/_all/elasticsearchprojects/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
);
}

[Test]
public void No_DefaultIndex_MappedType_Test()
{
TestUrl(
expected: "/_all/type1/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>(),
settings: new ConnectionSettings()
.MapDefaultTypeNames(m => m
.Add(typeof(ElasticsearchProject), "type1")
)
);
}

[Test]
public void MappedIndex_AllTypes_Test()
{
TestUrl(
expected: "/index1/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
.AllTypes(),
settings: new ConnectionSettings()
.MapDefaultTypeIndices(m => m
.Add(typeof(ElasticsearchProject), "index1")
)
);
}

[Test]
public void MappedIndex_MappedType_Test()
{
TestUrl(
expected: "/index1/type1/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>(),
settings: new ConnectionSettings()
.MapDefaultTypeIndices(m => m
.Add(typeof(ElasticsearchProject), "index1")
)
.MapDefaultTypeNames(m => m
.Add(typeof(ElasticsearchProject), "type1")
)
);
}

[Test]
public void MappedIndex_InferredType_Test()
{
TestUrl(
expected: "/index1/elasticsearchprojects/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>(),
settings: new ConnectionSettings()
.MapDefaultTypeIndices(m => m
.Add(typeof(ElasticsearchProject), "index1")
)
);
}

[Test]
public void MappedIndex_MultipleExplicitTypes_Test()
{
TestUrl(
expected: "/index1/type1,type2/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
.Types("type1", "type2"),
settings: new ConnectionSettings()
.MapDefaultTypeIndices(m => m
.Add(typeof(ElasticsearchProject), "index1")
)
);
}

[Test]
public void ExplicitIndex_AllTypes_Test()
{
TestUrl(
expected: "/index1/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
.Index("index1")
.AllTypes()
);
}

[Test]
public void ExplicitIndex_InferredType_Test()
{
TestUrl(
expected: "/index1/elasticsearchprojects/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
.Index("index1")
);
}

[Test]
public void ExplicitIndex_ExplicitType_Test()
{
TestUrl(
expected: "/index1/type1/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
.Index("index1")
.Type("type1")
);
}

[Test]
public void ExplicitIndex_MultipleExplicitTypes_Test()
{
TestUrl(
expected: "/index1/type1,type2/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
.Index("index1")
.Types("type1", "type2")
);
}

[Test]
public void MultipleExplicitIndices_MultipleExplicitTypes_Test()
{
TestUrl(
expected: "/index1,index2/type1,type2/_search",
descriptor: new SearchDescriptor<ElasticsearchProject>()
.Indices("index1", "index2")
.Types("type1", "type2")
);
}
}
}