Skip to content

Commit 9640a1a

Browse files
committed
Merge pull request #1252 from elasticsearch/fix/untyped-index-type-path-steal-type
fix #1251 Smarter untyped baseindextypepath
2 parents 912ab1f + 04b1e68 commit 9640a1a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Nest/DSL/Paths/IndexTypePathDescriptor.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@ public static void SetRouteParameters<TParameters>(
2424
var inferrer = new ElasticInferrer(settings);
2525

2626
if (path.Index == null)
27-
throw new DslException("Index() not specified");
27+
{
28+
if (path.Type != null && path.Type.Type != null)
29+
path.Index = path.Type.Type;
30+
else
31+
throw new DslException("Index() not specified");
32+
}
2833

2934
if (path.Type == null)
3035
throw new DslException("Type() not specified");
3136

3237
var index = inferrer.IndexName(path.Index);
33-
var type = inferrer.TypeName(path.Type);
38+
var type = inferrer.TypeName(path.Type);
3439

3540
pathInfo.Index = index;
3641
pathInfo.Type = type;
@@ -51,6 +56,7 @@ public static void SetRouteParameters<TParameters, T>(
5156
if (path.Type == null)
5257
path.Type = inferrer.TypeName<T>();
5358

59+
5460
var index = inferrer.IndexName(path.Index);
5561
var type = inferrer.TypeName(path.Type);
5662

src/Tests/Nest.Tests.Unit/BigBadUrlUnitTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public void TestAllTheUrls()
111111
Do("HEAD", "/mydefaultindex", c => c.IndexExists(h => h.Index<Doc>()));
112112
Do("HEAD", "/mydefaultindex/_alias/myalias", c => c.AliasExists(h => h.Index<Doc>().Name("myalias")));
113113
Do("HEAD", "/mydefaultindex/some-type", c => c.TypeExists(h => h.Index<Doc>().Type("some-type")));
114+
Do("HEAD", "/mydefaultindex/doc", c => c.TypeExists(h=>h.Type<Doc>()));
114115
Do("HEAD", "/_alias/myalias", c => c.AliasExists(new AliasExistsRequest("myalias")));
115116
Do("POST", "/_bulk", c => c.IndexMany(Enumerable.Range(0, 10).Select(i => new Doc {Id = i.ToString()})));
116117
Do("POST", "/customindex/customtype/_bulk", c =>

0 commit comments

Comments
 (0)