Skip to content

Commit 3e5262f

Browse files
committed
fix #907 using untyped SearchRequest() should still infer default index
1 parent a73b2ff commit 3e5262f

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

Diff for: src/Nest/DSL/Paths/QueryPathDescriptor.cs

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public static void SetRouteParameters<TParameters>(
3838
pathInfo.Index = inferrer.IndexNames(path.Indices);
3939
else if (path.AllIndices.GetValueOrDefault(false) && !pathInfo.Type.IsNullOrEmpty())
4040
pathInfo.Index = "_all";
41+
else if (!path.AllIndices.GetValueOrDefault(false) && pathInfo.Index.IsNullOrEmpty())
42+
pathInfo.Index = inferrer.DefaultIndex;
4143

4244
}
4345
public static void SetRouteParameters<TParameters, T>(

Diff for: src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@
235235
<Compile Include="ObjectInitializer\Aliases\GetAliasesRequestTests.cs" />
236236
<Compile Include="ObjectInitializer\Aliases\AliasRequestTests.cs" />
237237
<Compile Include="ObjectInitializer\Nodes\NodesHotThreadsRequestTests.cs" />
238+
<Compile Include="ObjectInitializer\Search\SearchRequestUntypedTests.cs" />
238239
<Compile Include="ObjectInitializer\Status\StatusRequestTests.cs" />
239240
<Compile Include="ObjectInitializer\IndicesStats\IndicesStatsRequestTests.cs" />
240241
<Compile Include="ObjectInitializer\ClusterState\ClusterStateRequestTests.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using Elasticsearch.Net;
6+
using FluentAssertions;
7+
using Nest.Resolvers;
8+
using Nest.Tests.MockData.Domain;
9+
using NUnit.Framework;
10+
11+
namespace Nest.Tests.Unit.ObjectInitializer.Search
12+
{
13+
[TestFixture]
14+
public class SearchRequestUntypedTests : BaseJsonTests
15+
{
16+
private readonly IElasticsearchResponse _status;
17+
18+
public SearchRequestUntypedTests()
19+
{
20+
QueryContainer query = new TermQuery()
21+
{
22+
Field = Property.Path<ElasticsearchProject>(p=>p.Name),
23+
Value = "value"
24+
} && new PrefixQuery()
25+
{
26+
Field = "prefix_field",
27+
Value = "prefi",
28+
Rewrite = RewriteMultiTerm.ConstantScoreBoolean
29+
};
30+
31+
var request = new SearchRequest
32+
{
33+
From = 0,
34+
Size = 20,
35+
Query = query
36+
37+
};
38+
var response = this._client.Search<ElasticsearchProject>(request);
39+
this._status = response.ConnectionStatus;
40+
}
41+
42+
[Test]
43+
public void Url()
44+
{
45+
this._status.RequestUrl.Should().EndWith("/nest_test_data/_search");
46+
this._status.RequestMethod.Should().Be("POST");
47+
}
48+
49+
}
50+
}

0 commit comments

Comments
 (0)