Skip to content

Commit 29e6b08

Browse files
committed
Fix #969: ignore_unavailable wasn't being added to the request body for _msearch
1 parent acf50dc commit 29e6b08

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

src/Nest/DSL/SearchDescriptor.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ public interface ISearchRequest : IQueryPath<SearchRequestParameters>
8282
string Preference { get; }
8383

8484
string Routing { get; }
85-
85+
8686
SearchType? SearchType { get; }
87-
87+
88+
bool? IgnoreUnavalable { get; }
89+
8890
Func<dynamic, Hit<dynamic>, Type> TypeSelector { get; set;}
8991

9092
SearchRequestParameters QueryString { get; set; }
@@ -172,6 +174,12 @@ string ISearchRequest.Routing
172174
: string.Join(",", routing);
173175
}
174176
}
177+
178+
bool? ISearchRequest.IgnoreUnavalable
179+
{
180+
get { return this.QueryString == null ? null : this.QueryString.GetQueryStringValue<bool?>("ignore_unavailable"); }
181+
}
182+
175183
public Func<dynamic, Hit<dynamic>, Type> TypeSelector { get; set; }
176184

177185
public SearchRequestParameters QueryString { get; set; }
@@ -233,6 +241,12 @@ string ISearchRequest.Routing
233241
: string.Join(",", routing);
234242
}
235243
}
244+
245+
bool? ISearchRequest.IgnoreUnavalable
246+
{
247+
get { return this.QueryString == null ? null : this.QueryString.GetQueryStringValue<bool?>("ignore_unavailable"); }
248+
}
249+
236250
public Func<dynamic, Hit<dynamic>, Type> TypeSelector { get; set; }
237251
public SearchRequestParameters QueryString { get; set; }
238252
}
@@ -273,6 +287,11 @@ string ISearchRequest.Routing
273287
}
274288
}
275289

290+
bool? ISearchRequest.IgnoreUnavalable
291+
{
292+
get { return this.Request.RequestParameters.GetQueryStringValue<bool?>("ignore_unavailable"); }
293+
}
294+
276295
Type ISearchRequest.ClrType { get { return typeof(T); } }
277296

278297
/// <summary>

src/Nest/ExposedInternals/NestSerializer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ public string SerializeMultiSearch(IMultiSearchRequest multiSearchRequest)
288288
type = path.Type,
289289
search_type = this.GetSearchType(operation, multiSearchRequest),
290290
preference = operation.Preference,
291-
routing = operation.Routing
291+
routing = operation.Routing,
292+
ignore_unavailable = operation.IgnoreUnavalable
292293
};
293294
var opJson = this.Serialize(op, SerializationFormatting.None).Utf8String();
294295

src/Tests/Nest.Tests.Integration/Core/MultiSearch/MultiSearchTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public void MultipleComplexSearches()
5858
{
5959
var result = this.Client.MultiSearch(b => b
6060
.Search<ElasticsearchProject>(s => s
61+
.IgnoreUnavailable()
6162
.Query(q=>q.Term(p=>p.Name, "NEST"))
6263
.Filter(f => f.Term(p => p.Name, "NEST"))
6364
.FacetTerm(tf=>tf.OnField(p=>p.Name).Global())

src/Tests/Nest.Tests.Unit/Core/MultiSearch/MultiSearchRespectsSearchTypePreferenceAndRouting.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/Tests/Nest.Tests.Unit/Core/MultiSearch/MultiSearchTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ public void MultiSearchFixedIndexAndType()
5555
uri.AbsolutePath.Should().Be("/myindex/mytype/_msearch");
5656
}
5757
[Test]
58-
public void MultiSearchRespectsSearchTypePreferenceAndRouting()
58+
public void MultiSearchHeaderParts()
5959
{
6060
var result = this._client.MultiSearch(b => b
6161
.FixedPath("myindex", "mytype")
6262
.Search<ElasticsearchProject>(s => s
63+
.IgnoreUnavailable()
6364
.Index("myindex2")
6465
.Type("mytype2")
6566
.MatchAll()
@@ -73,6 +74,7 @@ public void MultiSearchRespectsSearchTypePreferenceAndRouting()
7374
.Routing("customvalue2")
7475
.SearchType(SearchType.Count))
7576
.Search<ElasticsearchProject>(s => s
77+
.IgnoreUnavailable()
7678
.MatchAll()
7779
.Preference("_primary")
7880
.Routing("customvalue1")
@@ -87,9 +89,9 @@ public void MultiSearchRespectsSearchTypePreferenceAndRouting()
8789
uri.AbsolutePath.Should().Be("/myindex/mytype/_msearch");
8890
var results = new[]
8991
{
90-
@"{""index"":""myindex2"",""type"":""mytype2"",""search_type"":""dfs_query_and_fetch"",""preference"":""_primary"",""routing"":""customvalue1""}",
92+
@"{""index"":""myindex2"",""type"":""mytype2"",""search_type"":""dfs_query_and_fetch"",""preference"":""_primary"",""routing"":""customvalue1"",""ignore_unavailable"":true}",
9193
@"{""index"":""myindex2"",""type"":""mytype2"",""search_type"":""count"",""preference"":""_primary_first"",""routing"":""customvalue2""}",
92-
@"{""type"":""mytype"",""search_type"":""dfs_query_and_fetch"",""preference"":""_primary"",""routing"":""customvalue1""}",
94+
@"{""type"":""mytype"",""search_type"":""dfs_query_and_fetch"",""preference"":""_primary"",""routing"":""customvalue1"",""ignore_unavailable"":true}",
9395
@"{""type"":""mytype"",""search_type"":""count"",""preference"":""_primary_first"",""routing"":""customvalue2""}"
9496
};
9597

src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,6 @@
645645
<None Include="Core\MultiPercolate\MultiPercolateJson.json">
646646
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
647647
</None>
648-
<None Include="Core\MultiSearch\MultiSearchRespectsSearchTypePreferenceAndRouting.json">
649-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
650-
</None>
651648
<None Include="Core\UpdateSettings\AllUpdateSettings.json">
652649
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
653650
</None>

0 commit comments

Comments
 (0)