From 7398541ed8bf76ebb17bb687b7a24fd190035e86 Mon Sep 17 00:00:00 2001 From: gmarz Date: Thu, 19 Mar 2015 14:15:46 -0400 Subject: [PATCH 1/2] Fix ArgumentNullException in MultiSearch OIS when SearchRequest is untyped Closes #1279 --- .../Converters/MultiSearchConverter.cs | 2 +- .../Nest.Tests.Integration.csproj | 1 + .../Reproduce/Reproduce1279Tests.cs | 40 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/Tests/Nest.Tests.Integration/Reproduce/Reproduce1279Tests.cs diff --git a/src/Nest/Resolvers/Converters/MultiSearchConverter.cs b/src/Nest/Resolvers/Converters/MultiSearchConverter.cs index 47a7920ff17..d8e9c33542f 100644 --- a/src/Nest/Resolvers/Converters/MultiSearchConverter.cs +++ b/src/Nest/Resolvers/Converters/MultiSearchConverter.cs @@ -96,7 +96,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist { var descriptor = m.Descriptor.Value; var concreteTypeSelector = descriptor.TypeSelector; - var baseType = m.Descriptor.Value.ClrType; + var baseType = m.Descriptor.Value.ClrType ?? typeof(object); var generic = MakeDelegateMethodInfo.MakeGenericMethod(baseType); diff --git a/src/Tests/Nest.Tests.Integration/Nest.Tests.Integration.csproj b/src/Tests/Nest.Tests.Integration/Nest.Tests.Integration.csproj index ce6743c2e9f..b89d1606a64 100644 --- a/src/Tests/Nest.Tests.Integration/Nest.Tests.Integration.csproj +++ b/src/Tests/Nest.Tests.Integration/Nest.Tests.Integration.csproj @@ -178,6 +178,7 @@ + diff --git a/src/Tests/Nest.Tests.Integration/Reproduce/Reproduce1279Tests.cs b/src/Tests/Nest.Tests.Integration/Reproduce/Reproduce1279Tests.cs new file mode 100644 index 00000000000..1fac4bb30f4 --- /dev/null +++ b/src/Tests/Nest.Tests.Integration/Reproduce/Reproduce1279Tests.cs @@ -0,0 +1,40 @@ +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using FluentAssertions; +using Nest.Tests.MockData.Domain; +using Newtonsoft.Json.Linq; + +namespace Nest.Tests.Integration.Reproduce +{ + [TestFixture] + public class Reproduce1279Tests : IntegrationTests + { + [Test] + public void MultiSearchNullArgumentException() + { + var request = new MultiSearchRequest + { + Operations = new Dictionary + { + { "test", new SearchRequest + { + Query = new QueryContainer(new MatchAllQuery()), + Types = new TypeNameMarker[] { typeof(Product), typeof(ElasticsearchProject) }, + TypeSelector = (o, h) => typeof(ElasticsearchProject) + } + } + } + }; + + var result = Client.MultiSearch(request); + result.IsValid.Should().BeTrue(); + var response = result.GetResponse("test"); + var projects = response.Documents.OfType().ToList(); + projects.Count.Should().BeGreaterThan(0); + } + } +} From ffae0248132db5fabccf85356d8d37993993a324 Mon Sep 17 00:00:00 2001 From: gmarz Date: Thu, 19 Mar 2015 14:36:12 -0400 Subject: [PATCH 2/2] [Docs] Update MultiSearch OIS example --- docs/build/nest/core/multi-search.html | 8 ++++---- docs/contents/nest/core/multi-search.markdown | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/build/nest/core/multi-search.html b/docs/build/nest/core/multi-search.html index 357317621f6..1fe23d51dff 100644 --- a/docs/build/nest/core/multi-search.html +++ b/docs/build/nest/core/multi-search.html @@ -3,7 +3,7 @@

The multi search API allows to execute several search requests within the same API.

Fluent Syntax

var result = client.MultiSearch(ms => ms
-    .Search<ElasticsearchProject>("esproj", s => s.MatchAll())
+    .Search<ElasticsearchProject>("projects", s => s.MatchAll())
     .Search<Person>("people", s => s.MatchAll())
 );
 

Object Initializer Syntax

@@ -11,12 +11,12 @@

Fluent Syntax

{ Operations = new Dictionary<string, ISearchRequest> { - { "esproj", new SearchRequest + { "projects", new SearchRequest<ElasticsearchProject> { Query = new QueryContainer(new MatchAllQuery()) } }, - { "people", new SearchRequest + { "people", new SearchRequest<Person> { Query = new QueryContainer(new MatchAllQuery()) } @@ -28,7 +28,7 @@

Fluent Syntax

Handling the Multi Search Response

MultiSearch returns an IMultiSearchResponse object. Each SearchResponse<T> can be retrieved using the corresponding name that was specified in the request.

// returns a SearchResponse<ElasticsearchProject>>
-var projects = result.GetResponse<ElasticsearchProject>("esproj");
+var projects = result.GetResponse<ElasticsearchProject>("projects");
 
 // returns a SearchResponse<Person>>
 var people = result.GetResponse<Person>("people");
diff --git a/docs/contents/nest/core/multi-search.markdown b/docs/contents/nest/core/multi-search.markdown
index c0a6b38f329..0213fb7b5a6 100644
--- a/docs/contents/nest/core/multi-search.markdown
+++ b/docs/contents/nest/core/multi-search.markdown
@@ -13,7 +13,7 @@ The multi search API allows to execute several search requests within the same A
 ### Fluent Syntax
 
 	var result = client.MultiSearch(ms => ms
-		.Search("esproj", s => s.MatchAll())
+		.Search("projects", s => s.MatchAll())
 		.Search("people", s => s.MatchAll())
 	);
 
@@ -24,12 +24,12 @@ The multi search API allows to execute several search requests within the same A
 	{
 		Operations = new Dictionary
 		{
-			{ "esproj", new SearchRequest 
+			{ "projects", new SearchRequest
 				{ 
 					Query = new QueryContainer(new MatchAllQuery()) 
 				} 
 			},
-			{ "people", new SearchRequest 
+			{ "people", new SearchRequest
 				{ 
 					Query = new QueryContainer(new MatchAllQuery()) 
 				} 
@@ -44,7 +44,7 @@ The multi search API allows to execute several search requests within the same A
 `MultiSearch` returns an `IMultiSearchResponse` object.  Each `SearchResponse` can be retrieved using the corresponding name that was specified in the request.
 
 	// returns a SearchResponse>
-	var projects = result.GetResponse("esproj");
+	var projects = result.GetResponse("projects");
 
 	// returns a SearchResponse>
 	var people = result.GetResponse("people");