diff --git a/src/Filter.Nest/FilterLogic.cs b/src/Filter.Nest/FilterLogic.cs index abcfa2a..7f11907 100644 --- a/src/Filter.Nest/FilterLogic.cs +++ b/src/Filter.Nest/FilterLogic.cs @@ -138,12 +138,14 @@ internal static List, QueryContainer>> Generate throw new InvalidOperationException($"NEST filtering does not work on `Range` where `T` is `{filterProperty.PropertyType.Name}`."); } } - else - if (typeof(IEnumerable).IsAssignableFrom(filterProperty.PropertyType) + else if (typeof(IEnumerable).IsAssignableFrom(filterProperty.PropertyType) && filterProperty.PropertyType != typeof(string)) { foreach (var item in (IEnumerable)filterPropertyValue) { + if (item == null) + continue; + if (aliasAttribute != null) { queries.Add(x => diff --git a/tests/Filter.Nest.Tests/QueryContainerDescriptorExtensionsTests.cs b/tests/Filter.Nest.Tests/QueryContainerDescriptorExtensionsTests.cs index a2c8f11..5851081 100644 --- a/tests/Filter.Nest.Tests/QueryContainerDescriptorExtensionsTests.cs +++ b/tests/Filter.Nest.Tests/QueryContainerDescriptorExtensionsTests.cs @@ -99,6 +99,26 @@ public void Multiple_filter_properties_queried_as_collection_of_and_operators() } } + [Fact] + public void Null_string_array_item_does_not_throw_NullReferenceException() + { + using (var elasticsearch = new ElasticsearchInside.Elasticsearch()) + { + var elasticClient = new ElasticClient(new ConnectionSettings(elasticsearch.Url)); + + var camaro = new Car { Name = "Camaro", IsElectric = false }; + var volt = new Car { Name = "Volt", IsElectric = true }; + + elasticClient.Index(camaro, x => x.Index("vehicles")); + elasticClient.Index(volt, x => x.Index("vehicles")); + + elasticClient.Refresh("vehicles"); + + elasticClient.Search(s => s.Index("vehicles").Query( + q => q.MatchAll() && q.Filter(new { Name = new string[] { null } }))); + } + } + [Fact] public void Nullable_boolean_omitted_returns_expected_results() {