diff --git a/tests/Foundatio.Parsers.ElasticQueries.Tests/AggregationParserTests.cs b/tests/Foundatio.Parsers.ElasticQueries.Tests/AggregationParserTests.cs index 90997adf..27f56abb 100644 --- a/tests/Foundatio.Parsers.ElasticQueries.Tests/AggregationParserTests.cs +++ b/tests/Foundatio.Parsers.ElasticQueries.Tests/AggregationParserTests.cs @@ -34,18 +34,18 @@ await Client.IndexManyAsync([ var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index).UseGeo(_ => "51.5032520,-0.1278990")); var aggregations = await processor.BuildAggregationsAsync("min:field4"); - var actualResponse = Client.Search(d => d.Index(index).Aggregations(aggregations)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(aggregations)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Aggregations(a => a + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(a => a .Min("min_field4", c => c.Field("field4").Meta(m => m.Add("@field_type", "long"))))); string expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); Assert.Equal(expectedRequest, actualRequest); - Assert.True(actualResponse.IsValid); - Assert.True(expectedResponse.IsValid); + Assert.True(actualResponse.IsValidResponse); + Assert.True(expectedResponse.IsValidResponse); Assert.Equal(expectedResponse.Total, actualResponse.Total); } @@ -66,18 +66,18 @@ await Client.IndexManyAsync([ var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index).UseFieldMap(fieldMap).UseGeo(_ => "51.5032520,-0.1278990")); var aggregations = await processor.BuildAggregationsAsync("min:heynow"); - var actualResponse = Client.Search(d => d.Index(index).Aggregations(aggregations)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(aggregations)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Aggregations(a => a + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(a => a .Min("min_heynow", c => c.Field("field4").Meta(m => m.Add("@field_type", "long"))))); string expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); Assert.Equal(expectedRequest, actualRequest); - Assert.True(actualResponse.IsValid); - Assert.True(expectedResponse.IsValid); + Assert.True(actualResponse.IsValidResponse); + Assert.True(expectedResponse.IsValidResponse); Assert.Equal(expectedResponse.Total, actualResponse.Total); } @@ -102,18 +102,18 @@ await Client.IndexManyAsync([ var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index).UseFieldMap(fieldMap)); var aggregations = await processor.BuildAggregationsAsync("terms:heynow"); - var actualResponse = Client.Search(d => d.Index(index).Aggregations(aggregations)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(aggregations)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Aggregations(a => a + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(a => a .Terms("terms_heynow", c => c.Field("field1.keyword").Meta(m => m.Add("@field_type", "text"))))); string expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); Assert.Equal(expectedRequest, actualRequest); - Assert.True(actualResponse.IsValid); - Assert.True(expectedResponse.IsValid); + Assert.True(actualResponse.IsValidResponse); + Assert.True(expectedResponse.IsValidResponse); Assert.Equal(expectedResponse.Total, actualResponse.Total); } @@ -133,11 +133,11 @@ await Client.IndexManyAsync([ var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index).UseGeo(_ => "51.5032520,-0.1278990")); var aggregations = await processor.BuildAggregationsAsync("min:field4 max:field4 avg:field4 sum:field4 percentiles:field4~50,100 cardinality:field4 missing:field2 date:field5 histogram:field4 geogrid:field3 terms:field1"); - var actualResponse = Client.Search(d => d.Index(index).Aggregations(aggregations)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(aggregations)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Aggregations(a => a + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(a => a .GeoHash("geogrid_field3", h => h.Field("field3").GeoHashPrecision(1) .Aggregations(a1 => a1.Average("avg_lat", s => s.Script(ss => ss.Source("doc['field3'].lat"))).Average("avg_lon", s => s.Script(ss => ss.Source("doc['field3'].lon"))))) .Terms("terms_field1", t => t.Field("field1.keyword").Meta(m => m.Add("@field_type", "text"))) @@ -154,8 +154,8 @@ await Client.IndexManyAsync([ _logger.LogInformation("Expected: {Request}", expectedRequest); Assert.Equal(expectedRequest, actualRequest); - Assert.True(actualResponse.IsValid); - Assert.True(expectedResponse.IsValid); + Assert.True(actualResponse.IsValidResponse); + Assert.True(expectedResponse.IsValidResponse); Assert.Equal(expectedResponse.Total, actualResponse.Total); } @@ -176,19 +176,19 @@ public async Task ProcessNestedAggregationsWithAliasesAsync() var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index).UseFieldMap(aliasMap)); var aggregations = await processor.BuildAggregationsAsync("terms:(alias1 cardinality:user)"); - var actualResponse = Client.Search(d => d.Index(index).Aggregations(aggregations)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(aggregations)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Aggregations(a => a + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(a => a .Terms("terms_alias1", t => t.Field("field1.keyword").Meta(m => m.Add("@field_type", "keyword")) .Aggregations(a1 => a1.Cardinality("cardinality_user", c => c.Field("data.@user.identity.keyword")))))); string expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); Assert.Equal(expectedRequest, actualRequest); - Assert.True(actualResponse.IsValid); - Assert.True(expectedResponse.IsValid); + Assert.True(actualResponse.IsValidResponse); + Assert.True(expectedResponse.IsValidResponse); Assert.Equal(expectedResponse.Total, actualResponse.Total); } @@ -206,19 +206,19 @@ await Client.IndexManyAsync([ var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index).UseFieldMap(aliasMap)); var aggregations = await processor.BuildAggregationsAsync("missing:alias2"); - var actualResponse = Client.Search(d => d.Index(index).Aggregations(aggregations)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(aggregations)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Aggregations(a => a + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(a => a .Missing("missing_alias2", t => t.Field("field2.keyword")))); string expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); Assert.Equal(expectedRequest, actualRequest); - Assert.True(actualResponse.IsValid); - Assert.True(expectedResponse.IsValid); + Assert.True(actualResponse.IsValidResponse); + Assert.True(expectedResponse.IsValidResponse); Assert.Equal(expectedResponse.Total, actualResponse.Total); } @@ -240,11 +240,11 @@ await Client.IndexManyAsync([ var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index).UseGeo(_ => "51.5032520,-0.1278990").UseFieldMap(aliasMap)); var aggregations = await processor.BuildAggregationsAsync("min:alias4 max:alias4 avg:alias4 sum:alias4 percentiles:alias4 cardinality:user missing:alias2 date:alias5 histogram:alias4 geogrid:alias3 terms:alias1"); - var actualResponse = Client.Search(d => d.Index(index).Aggregations(aggregations)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(aggregations)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Aggregations(a => a + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(a => a .GeoHash("geogrid_alias3", h => h.Field("field3").GeoHashPrecision(1) .Aggregations(a1 => a1.Average("avg_lat", s => s.Script(ss => ss.Source("doc['field3'].lat"))).Average("avg_lon", s => s.Script(ss => ss.Source("doc['field3'].lon"))))) .Terms("terms_alias1", t => t.Field("field1.keyword").Meta(m => m.Add("@field_type", "text"))) @@ -261,8 +261,8 @@ await Client.IndexManyAsync([ _logger.LogInformation("Expected: {Request}", expectedRequest); Assert.Equal(expectedRequest, actualRequest); - Assert.True(actualResponse.IsValid); - Assert.True(expectedResponse.IsValid); + Assert.True(actualResponse.IsValidResponse); + Assert.True(expectedResponse.IsValidResponse); Assert.Equal(expectedResponse.Total, actualResponse.Total); } @@ -276,11 +276,11 @@ public async Task ProcessTermAggregations() var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index)); var aggregations = await processor.BuildAggregationsAsync("terms:(field1 @exclude:myexclude @include:myinclude @include:otherinclude @missing:mymissing @exclude:otherexclude @min:1)"); - var actualResponse = Client.Search(d => d.Index(index).Aggregations(aggregations)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(aggregations)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Aggregations(a => a + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(a => a .Terms("terms_field1", t => t .Field("field1.keyword") .MinimumDocumentCount(1) @@ -305,11 +305,11 @@ public async Task ProcessHistogramIntervalAggregations() var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index)); var aggregations = await processor.BuildAggregationsAsync("histogram:(field1~0.1)"); - var actualResponse = Client.Search(d => d.Index(index).Aggregations(aggregations)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(aggregations)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Aggregations(a => a + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(a => a .Histogram("histogram_field1", t => t .Field("field1.keyword") .Interval(0.1) @@ -332,11 +332,11 @@ public async Task ProcessTermTopHitsAggregations() var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index)); var aggregations = await processor.BuildAggregationsAsync("terms:(field1~1000^2 tophits:(_~1000 @include:myinclude))"); - var actualResponse = Client.Search(d => d.Index(index).Aggregations(aggregations)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(aggregations)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Aggregations(a => a + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(a => a .Terms("terms_field1", t => t .Field("field1.keyword") .Size(1000) @@ -360,11 +360,11 @@ public async Task ProcessSortedTermAggregations() var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index)); var aggregations = await processor.BuildAggregationsAsync("terms:(field1 -cardinality:field4)"); - var actualResponse = Client.Search(d => d.Index(index).Aggregations(aggregations)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(aggregations)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Aggregations(a => a + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(a => a .Terms("terms_field1", t => t .Field("field1.keyword") .Order(o => o.Descending("cardinality_field4")) @@ -375,8 +375,8 @@ public async Task ProcessSortedTermAggregations() _logger.LogInformation("Expected: {Request}", expectedRequest); Assert.Equal(expectedRequest, actualRequest); - Assert.True(actualResponse.IsValid); - Assert.True(expectedResponse.IsValid); + Assert.True(actualResponse.IsValidResponse); + Assert.True(expectedResponse.IsValidResponse); Assert.Equal(expectedResponse.Total, actualResponse.Total); } @@ -390,11 +390,11 @@ public async Task ProcessDateHistogramAggregations() var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index)); var aggregations = await processor.BuildAggregationsAsync("date:(field5^1h @missing:\"0001-01-01T00:00:00\" min:field5^1h max:field5^1h)"); - var actualResponse = Client.Search(d => d.Index(index).Aggregations(aggregations)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(aggregations)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Aggregations(a => a + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(a => a .DateHistogram("date_field5", d1 => d1 .Field("field5").Meta(m => m.Add("@timezone", "1h")) .CalendarInterval(DateInterval.Day) @@ -409,8 +409,8 @@ public async Task ProcessDateHistogramAggregations() _logger.LogInformation("Expected: {Request}", expectedRequest); Assert.Equal(expectedRequest, actualRequest); - Assert.True(actualResponse.IsValid, actualResponse.DebugInformation); - Assert.True(expectedResponse.IsValid); + Assert.True(actualResponse.IsValidResponse, actualResponse.DebugInformation); + Assert.True(expectedResponse.IsValidResponse); Assert.Equal(expectedResponse.Total, actualResponse.Total); } @@ -424,11 +424,11 @@ public async Task CanSpecifyDefaultValuesAggregations() var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index)); var aggregations = await processor.BuildAggregationsAsync("min:field4~0 max:field4~0 avg:field4~0 sum:field4~0 cardinality:field4~0"); - var actualResponse = Client.Search(d => d.Index(index).Aggregations(aggregations)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(aggregations)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Aggregations(a => a + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(a => a .Sum("sum_field4", c => c.Field("field4").Missing(0).Meta(m => m.Add("@field_type", "integer"))) .Cardinality("cardinality_field4", c => c.Field("field4").Missing(0)) .Average("avg_field4", c => c.Field("field4").Missing(0).Meta(m => m.Add("@field_type", "integer"))) @@ -438,8 +438,8 @@ public async Task CanSpecifyDefaultValuesAggregations() _logger.LogInformation("Expected: {Request}", expectedRequest); Assert.Equal(expectedRequest, actualRequest); - Assert.True(actualResponse.IsValid); - Assert.True(expectedResponse.IsValid); + Assert.True(actualResponse.IsValidResponse); + Assert.True(expectedResponse.IsValidResponse); Assert.Equal(expectedResponse.Total, actualResponse.Total); } @@ -463,10 +463,10 @@ public Task GeoGridDoesNotResolveLocationForAggregation() [InlineData("avg:value", true)] [InlineData(" avg : value", true)] [InlineData("avg:value cardinality:value sum:value min:value max:value", true)] - public Task CanParseAggregations(string query, bool isValid) + public Task CanParseAggregations(string query, bool IsValidResponse) { var parser = new ElasticQueryParser(c => c.SetLoggerFactory(Log)); - return GetAggregationQueryInfoAsync(parser, query, isValid); + return GetAggregationQueryInfoAsync(parser, query, IsValidResponse); } public static IEnumerable AggregationTestCases => @@ -525,23 +525,23 @@ public Task CanParseAggregations(string query, bool isValid) [Theory] [MemberData(nameof(AggregationTestCases))] - public Task GetElasticAggregationQueryInfoAsync(string query, bool isValid, int maxNodeDepth, HashSet fields, Dictionary> operations) + public Task GetElasticAggregationQueryInfoAsync(string query, bool IsValidResponse, int maxNodeDepth, HashSet fields, Dictionary> operations) { var parser = new ElasticQueryParser(c => c.SetLoggerFactory(Log)); - return GetAggregationQueryInfoAsync(parser, query, isValid, maxNodeDepth, fields, operations); + return GetAggregationQueryInfoAsync(parser, query, IsValidResponse, maxNodeDepth, fields, operations); } - private async Task GetAggregationQueryInfoAsync(IQueryParser parser, string query, bool isValid, int maxNodeDepth = -1, HashSet fields = null, Dictionary> operations = null) + private async Task GetAggregationQueryInfoAsync(IQueryParser parser, string query, bool IsValidResponse, int maxNodeDepth = -1, HashSet fields = null, Dictionary> operations = null) { var context = new ElasticQueryVisitorContext { QueryType = QueryTypes.Aggregation }; var queryNode = await parser.ParseAsync(query, context); var result = context.GetValidationResult(); Assert.Equal(QueryTypes.Aggregation, result.QueryType); - if (!result.IsValid) + if (!result.IsValidResponse) _logger.LogInformation(result.Message); - Assert.Equal(isValid, result.IsValid); + Assert.Equal(IsValidResponse, result.IsValidResponse); if (maxNodeDepth >= 0) Assert.Equal(maxNodeDepth, result.MaxNodeDepth); if (fields != null) diff --git a/tests/Foundatio.Parsers.ElasticQueries.Tests/CustomVisitorTests.cs b/tests/Foundatio.Parsers.ElasticQueries.Tests/CustomVisitorTests.cs index 171d5b7e..e1844557 100644 --- a/tests/Foundatio.Parsers.ElasticQueries.Tests/CustomVisitorTests.cs +++ b/tests/Foundatio.Parsers.ElasticQueries.Tests/CustomVisitorTests.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Text; using System.Threading.Tasks; +using Elastic.Clients.Elasticsearch.QueryDsl; using Foundatio.Parsers.ElasticQueries.Extensions; using Foundatio.Parsers.LuceneQueries.Nodes; using Foundatio.Parsers.LuceneQueries.Visitors; @@ -15,14 +16,14 @@ public class CustomVisitorTests : ElasticsearchTestBase { public CustomVisitorTests(ITestOutputHelper output, ElasticsearchFixture fixture) : base(output, fixture) { - Log.DefaultMinimumLevel = Microsoft.Extensions.Logging.LogLevel.Trace; + Log.DefaultMinimumLevel = LogLevel.Trace; } [Fact] public async Task CanResolveSimpleCustomFilter() { string index = CreateRandomIndex(); - Client.Index(new MyType { Id = "1" }, i => i.Index(index)); + await Client.IndexAsync(new MyType { Id = "1" }, i => i.Index(index)); var processor = new ElasticQueryParser(c => c .SetLoggerFactory(Log) @@ -30,11 +31,11 @@ public async Task CanResolveSimpleCustomFilter() .AddVisitor(new CustomFilterVisitor())); var result = await processor.BuildQueryAsync("@custom:(one)"); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d + var expectedResponse = await Client.SearchAsync(d => d .Index(index).Query(f => f.Bool(b => b.Filter(filter => filter.Terms(m => m.Field("id").Terms("1")))))); string expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); @@ -47,7 +48,7 @@ public async Task CanResolveSimpleCustomFilter() public async Task CanResolveCustomFilterContainingIncludes() { string index = CreateRandomIndex(); - Client.Index(new MyType { Id = "1" }, i => i.Index(index)); + await Client.IndexAsync(new MyType { Id = "1" }, i => i.Index(index)); var processor = new ElasticQueryParser(c => c .SetLoggerFactory(Log) @@ -55,11 +56,11 @@ public async Task CanResolveCustomFilterContainingIncludes() .AddVisitor(new CustomFilterVisitor())); var result = await processor.BuildQueryAsync("@custom:(one @include:3)"); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d + var expectedResponse = await Client.SearchAsync(d => d .Index(index).Query(f => f.Bool(b => b.Filter(filter => filter.Terms(m => m.Field("id").Terms("1", "3")))))); string expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); @@ -72,7 +73,7 @@ public async Task CanResolveCustomFilterContainingIncludes() public async Task CanResolveIncludeToCustomFilterContainingIgnoredInclude() { string index = CreateRandomIndex(); - Client.Index(new MyType { Id = "1" }, i => i.Index(index)); + await Client.IndexAsync(new MyType { Id = "1" }, i => i.Index(index)); var processor = new ElasticQueryParser(c => c .SetLoggerFactory(Log) @@ -80,11 +81,11 @@ public async Task CanResolveIncludeToCustomFilterContainingIgnoredInclude() .AddVisitor(new CustomFilterVisitor(), 1)); var result = await processor.BuildQueryAsync("@include:test"); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d + var expectedResponse = await Client.SearchAsync(d => d .Index(index).Query(f => f.Bool(b => b.Filter(filter => filter.Terms(m => m.Field("id").Terms("1", "3")))))); string expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); @@ -119,7 +120,7 @@ private static Task ResolveIncludeAsync(string expected, string actual, public async Task CanResolveMultipleCustomFilters() { string index = CreateRandomIndex(); - Client.Index(new MyType { Id = "1" }, i => i.Index(index)); + await Client.IndexAsync(new MyType { Id = "1" }, i => i.Index(index)); var processor = new ElasticQueryParser(c => c .SetLoggerFactory(Log) @@ -127,11 +128,11 @@ public async Task CanResolveMultipleCustomFilters() .AddVisitor(new CustomFilterVisitor())); var result = await processor.BuildQueryAsync("@custom:(one) OR (field1:Test @custom:(two))"); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index) + var expectedResponse = await Client.SearchAsync(d => d.Index(index) .Query(f => f .Bool(b => b .Filter(filter => filter @@ -170,7 +171,7 @@ public override async Task VisitAsync(GroupNode node, IQueryVisitorContext conte { string term = ToTerm(node); var ids = await GetIdsAsync(term); - if (ids != null && ids.Count > 0) + if (ids is { Count: > 0 }) node.Parent.SetQuery(new TermsQuery { Field = "id", Terms = ids }); else node.Parent.SetQuery(new TermQuery { Field = "id", Value = "none" }); diff --git a/tests/Foundatio.Parsers.ElasticQueries.Tests/ElasticMappingResolverTests.cs b/tests/Foundatio.Parsers.ElasticQueries.Tests/ElasticMappingResolverTests.cs index 59ea0f6c..1e1577b1 100644 --- a/tests/Foundatio.Parsers.ElasticQueries.Tests/ElasticMappingResolverTests.cs +++ b/tests/Foundatio.Parsers.ElasticQueries.Tests/ElasticMappingResolverTests.cs @@ -1,5 +1,8 @@ using System; using System.Linq.Expressions; +using System.Threading.Tasks; +using Elastic.Clients.Elasticsearch; +using Elastic.Clients.Elasticsearch.Mapping; using Xunit; using Xunit.Abstractions; @@ -27,11 +30,11 @@ private TypeMapping MapMyNestedType(TypeMappingDescriptor m) } [Fact] - public void CanResolveCodedProperty() + public async Task CanResolveCodedProperty() { string index = CreateRandomIndex(MapMyNestedType); - Client.IndexMany([ + await Client.IndexManyAsync([ new MyNestedType { Field1 = "value1", @@ -52,7 +55,8 @@ public void CanResolveCodedProperty() new MyNestedType { Field1 = "value2", Field2 = "value2" }, new MyNestedType { Field1 = "value1", Field2 = "value4" } ], index); - Client.Indices.Refresh(index); + + await Client.Indices.RefreshAsync(index); var resolver = ElasticMappingResolver.Create(MapMyNestedType, Client, index, _logger); @@ -62,11 +66,11 @@ public void CanResolveCodedProperty() } [Fact] - public void CanResolveProperties() + public async Task CanResolveProperties() { string index = CreateRandomIndex(MapMyNestedType); - Client.IndexMany([ + await Client.IndexManyAsync([ new MyNestedType { Field1 = "value1", @@ -87,7 +91,7 @@ public void CanResolveProperties() new MyNestedType { Field1 = "value2", Field2 = "value2" }, new MyNestedType { Field1 = "value1", Field2 = "value4" } ], index); - Client.Indices.Refresh(index); + await Client.Indices.RefreshAsync(index); var resolver = ElasticMappingResolver.Create(MapMyNestedType, Client, index, _logger); diff --git a/tests/Foundatio.Parsers.ElasticQueries.Tests/ElasticQueryParserTests.cs b/tests/Foundatio.Parsers.ElasticQueries.Tests/ElasticQueryParserTests.cs index 92b58a8b..104e9eee 100644 --- a/tests/Foundatio.Parsers.ElasticQueries.Tests/ElasticQueryParserTests.cs +++ b/tests/Foundatio.Parsers.ElasticQueries.Tests/ElasticQueryParserTests.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using Elastic.Clients.Elasticsearch; +using Elastic.Clients.Elasticsearch.Aggregations; using Elastic.Clients.Elasticsearch.Mapping; using Elastic.Clients.Elasticsearch.QueryDsl; using Foundatio.Parsers.ElasticQueries.Extensions; @@ -88,11 +89,11 @@ await Client.IndexManyAsync([ var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log)); var result = await processor.BuildQueryAsync("field1:value1"); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Query(q => q.Bool(b => b.Filter(f => f.Term(m => m.Field1, "value1"))))); + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Query(q => q.Bool(b => b.Filter(f => f.Term(m => m.Field1, "value1"))))); string expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); @@ -117,11 +118,11 @@ await Client.IndexManyAsync([ var processor = new ElasticQueryParser(c => c.UseIncludes(includes).SetLoggerFactory(Log)); var result = await processor.BuildQueryAsync("field1:value1 @include:stuff", new ElasticQueryVisitorContext { UseScoring = true }); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Query(f => + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Query(f => f.Term(m => m.Field1, "value1") && f.Term(m => m.Field2, "value2"))); @@ -142,11 +143,11 @@ public async Task ShouldGenerateORedTermsQuery() var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log)); var result = await processor.BuildQueryAsync("field1:value1 field2:value2 field3:value3", new ElasticQueryVisitorContext().UseSearchMode()); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Query(f => + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Query(f => f.Term(m => m.Field1, "value1") || f.Term(m => m.Field2, "value2") || f.Term(m => m.Field3, "value3"))); string expectedRequest = expectedResponse.GetRequest(); @@ -171,11 +172,11 @@ public async Task ShouldHandleMultipleTermsForAnalyzedFields() var result = await processor.BuildQueryAsync("field1:(value1 abc def ghi) field2:(value2 jhk)", new ElasticQueryVisitorContext().UseSearchMode()); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Query(f => + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Query(f => f.Match(m => m.Field(mf => mf.Field1).Query("value1")) || f.Match(m => m.Field(mf => mf.Field1).Query("abc")) || f.Match(m => m.Field(mf => mf.Field1).Query("def")) @@ -190,11 +191,11 @@ public async Task ShouldHandleMultipleTermsForAnalyzedFields() processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).SetDefaultFields(["field1"]).UseMappings(Client, index)); result = await processor.BuildQueryAsync("value1 abc def ghi", new ElasticQueryVisitorContext().UseSearchMode()); - actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - expectedResponse = Client.Search(d => d.Index(index).Query(f => + expectedResponse = await Client.SearchAsync(d => d.Index(index).Query(f => f.Match(m => m.Field(mf => mf.Field1).Query("value1")) || f.Match(m => m.Field(mf => mf.Field1).Query("abc")) || f.Match(m => m.Field(mf => mf.Field1).Query("def")) @@ -209,11 +210,11 @@ public async Task ShouldHandleMultipleTermsForAnalyzedFields() // multi-match on multiple default fields processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).SetDefaultFields(["field1", "field2"]).UseMappings(Client, index)); result = await processor.BuildQueryAsync("value1 abc def ghi", new ElasticQueryVisitorContext().UseSearchMode()); - actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - expectedResponse = Client.Search(d => d.Index(index).Query(f => + expectedResponse = await Client.SearchAsync(d => d.Index(index).Query(f => f.MultiMatch(m => m.Fields(mf => mf.Fields("field1", "field2")).Query("value1")) || f.MultiMatch(m => m.Fields(mf => mf.Fields("field1", "field2")).Query("abc")) || f.MultiMatch(m => m.Fields(mf => mf.Fields("field1", "field2")).Query("def")) @@ -241,7 +242,7 @@ TypeMappingDescriptor GetCodeMappings(TypeMappingDescriptor d) = .Keyword(e => e.Name(m => m.Field2)))); var res = Client.Index(new MyType { Field1 = "value1", Field2 = "value2", Field4 = 1, Field5 = DateTime.Now }, i => i.Index(index)); - Client.Indices.Refresh(index); + Client.Indices.RefreshAsync(index); var parser = new ElasticQueryParser(c => c.SetDefaultFields(["field1"]).UseMappings(GetCodeMappings, Client, index)); @@ -269,11 +270,11 @@ await Client.IndexManyAsync([ var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index)); var result = await processor.BuildQueryAsync("\"\\\"now there\""); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(true); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index) + var expectedResponse = await Client.SearchAsync(d => d.Index(index) .Query(q => q .Bool(b => b .Filter(f => f @@ -297,11 +298,11 @@ await Client.IndexManyAsync([ var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index)); var result = await processor.BuildQueryAsync(@"field1:one\\/two*"); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(true); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index) + var expectedResponse = await Client.SearchAsync(d => d.Index(index) .Query(q => q .Bool(b => b .Filter(f => f @@ -325,11 +326,11 @@ await Client.IndexManyAsync([ var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index)); var result = await processor.BuildQueryAsync(@"field1:one\\/two"); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(true); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index) + var expectedResponse = await Client.SearchAsync(d => d.Index(index) .Query(q => q .Bool(b => b .Filter(f => f @@ -355,11 +356,11 @@ await Client.IndexManyAsync([ var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log)); var result = await processor.BuildQueryAsync($"_exists_:{nameof(MyType.Field2)}"); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d + var expectedResponse = await Client.SearchAsync(d => d .Index(index) .Query(q => q.Bool(b => b.Filter(f => f.Exists(e => e.Field(nameof(MyType.Field2))))))); string expectedRequest = expectedResponse.GetRequest(); @@ -383,11 +384,11 @@ await Client.IndexManyAsync([ var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log)); var result = await processor.BuildQueryAsync($"_missing_:{nameof(MyType.Field2)}", new ElasticQueryVisitorContext { UseScoring = true }); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d + var expectedResponse = await Client.SearchAsync(d => d .Index(index) .Query(q => q.Bool(b => b.MustNot(f => f.Exists(e => e.Field(nameof(MyType.Field2))))))); string expectedRequest = expectedResponse.GetRequest(); @@ -410,16 +411,16 @@ await Client.IndexManyAsync([ var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index)); var result = await processor.BuildAggregationsAsync("min:field2 max:field2 date:(field5~1d^\"America/Chicago\" min:field2 max:field2 min:field1 @offset:-6h)"); - var actualResponse = Client.Search(d => d.Index(index).Aggregations(result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(i => i.Index(index).Aggregations(f => f + var expectedResponse = await Client.SearchAsync(i => i.Index(index).Aggregations(f => f .Max("max_field2", m => m.Field("field2.keyword").Meta(m2 => m2.Add("@field_type", "text"))) .DateHistogram("date_field5", d => d.Field(d2 => d2.Field5) - .CalendarInterval(DateInterval.Day) + .CalendarInterval(CalendarInterval.Day) .Format("date_optional_time") .MinimumDocumentCount(0) .TimeZone("America/Chicago") @@ -442,32 +443,32 @@ await Client.IndexManyAsync([ /// /// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html /// - [InlineData("1s", DateInterval.Second)] - [InlineData("second", DateInterval.Second)] - [InlineData("m", DateInterval.Minute)] - [InlineData("1m", DateInterval.Minute)] - [InlineData("minute", DateInterval.Minute)] + [InlineData("1s", CalendarInterval.Second)] + [InlineData("second", CalendarInterval.Second)] + [InlineData("m", CalendarInterval.Minute)] + [InlineData("1m", CalendarInterval.Minute)] + [InlineData("minute", CalendarInterval.Minute)] [InlineData("23m")] - [InlineData("h", DateInterval.Hour)] - [InlineData("1h", DateInterval.Hour)] - [InlineData("hour", DateInterval.Hour)] + [InlineData("h", CalendarInterval.Hour)] + [InlineData("1h", CalendarInterval.Hour)] + [InlineData("hour", CalendarInterval.Hour)] [InlineData("1.5h")] - [InlineData("d", DateInterval.Day)] - [InlineData("1d", DateInterval.Day)] - [InlineData("day", DateInterval.Day)] + [InlineData("d", CalendarInterval.Day)] + [InlineData("1d", CalendarInterval.Day)] + [InlineData("day", CalendarInterval.Day)] [InlineData("2d")] - [InlineData("w", DateInterval.Week)] - [InlineData("1w", DateInterval.Week)] - [InlineData("week", DateInterval.Week)] - [InlineData("M", DateInterval.Month)] - [InlineData("1M", DateInterval.Month)] - [InlineData("month", DateInterval.Month)] - [InlineData("q", DateInterval.Quarter)] - [InlineData("1q", DateInterval.Quarter)] - [InlineData("quarter", DateInterval.Quarter)] - [InlineData("y", DateInterval.Year)] - [InlineData("1y", DateInterval.Year)] - [InlineData("year", DateInterval.Year)] + [InlineData("w", CalendarInterval.Week)] + [InlineData("1w", CalendarInterval.Week)] + [InlineData("week", CalendarInterval.Week)] + [InlineData("M", CalendarInterval.Month)] + [InlineData("1M", CalendarInterval.Month)] + [InlineData("month", CalendarInterval.Month)] + [InlineData("q", CalendarInterval.Quarter)] + [InlineData("1q", CalendarInterval.Quarter)] + [InlineData("quarter", CalendarInterval.Quarter)] + [InlineData("y", CalendarInterval.Year)] + [InlineData("1y", CalendarInterval.Year)] + [InlineData("year", CalendarInterval.Year)] [Theory] public async Task CanUseDateHistogramAggregationInterval(string interval, object expectedInterval = null) { @@ -478,17 +479,17 @@ public async Task CanUseDateHistogramAggregationInterval(string interval, object var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index)); var result = await processor.BuildAggregationsAsync($"date:(field5~{interval})"); - var actualResponse = Client.Search(d => d.Index(index).Aggregations(result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(i => i.Index(index).Aggregations(f => f + var expectedResponse = await Client.SearchAsync(i => i.Index(index).Aggregations(f => f .DateHistogram("date_field5", d => { d.Field(d2 => d2.Field5); - if (expectedInterval is DateInterval dateInterval) - d.CalendarInterval(dateInterval); + if (expectedInterval is CalendarInterval CalendarInterval) + d.CalendarInterval(CalendarInterval); else if (expectedInterval is string stringInterval) d.FixedInterval(stringInterval); else @@ -511,14 +512,14 @@ public async Task CanUseDateHistogramAggregationInterval(string interval, object public void CanDoNestDateHistogram() { string index = CreateRandomIndex(); - Client.IndexMany([new MyType { Field5 = DateTime.Now }], index); - Client.Indices.Refresh(index); + await Client.IndexManyAsync([new MyType { Field5 = DateTime.Now }], index); + Client.Indices.RefreshAsync(index); - var response = Client.Search(i => i.Index(index).Aggregations(f => f - .DateHistogram("myagg", d => d.Field(d2 => d2.Field5).CalendarInterval(DateInterval.Day)) + var response = await Client.SearchAsync(i => i.Index(index).Aggregations(f => f + .DateHistogram("myagg", d => d.Field(d2 => d2.Field5).CalendarInterval(CalendarInterval.Day)) )); - Assert.True(response.IsValid); + Assert.True(response.IsValidResponse); } [Fact] @@ -534,12 +535,12 @@ await Client.IndexManyAsync([ var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log)); var result = await processor.BuildAggregationsAsync("date:field5"); - var actualResponse = Client.Search(d => d.Index(index).Aggregations(result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Aggregations(result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(i => i.Index(index).Aggregations(f => f - .DateHistogram("date_field5", d => d.Field(d2 => d2.Field5).CalendarInterval(DateInterval.Day).Format("date_optional_time").MinimumDocumentCount(0)) + var expectedResponse = await Client.SearchAsync(i => i.Index(index).Aggregations(f => f + .DateHistogram("date_field5", d => d.Field(d2 => d2.Field5).CalendarInterval(CalendarInterval.Day).Format("date_optional_time").MinimumDocumentCount(0)) )); string expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); @@ -564,11 +565,11 @@ await Client.IndexManyAsync([ var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index)); var result = await processor.BuildQueryAsync("field1:value1", new ElasticQueryVisitorContext().UseSearchMode()); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Query(q => q.Match(e => e.Field(m => m.Field1).Query("value1")))); + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Query(q => q.Match(e => e.Field(m => m.Field1).Query("value1")))); string expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); @@ -576,10 +577,10 @@ await Client.IndexManyAsync([ Assert.Equal(expectedResponse.Total, actualResponse.Total); result = await processor.BuildQueryAsync("field3:hey", new ElasticQueryVisitorContext().UseSearchMode()); - actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - expectedResponse = Client.Search(d => d.Index(index).Query(q => q.Match(m => m + expectedResponse = await Client.SearchAsync(d => d.Index(index).Query(q => q.Match(m => m .Field(f => f.Field3) .Query("hey") ))); @@ -590,10 +591,10 @@ await Client.IndexManyAsync([ Assert.Equal(expectedResponse.Total, actualResponse.Total); result = await processor.BuildQueryAsync("field3:\"hey now\"", new ElasticQueryVisitorContext().UseSearchMode()); - actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - expectedResponse = Client.Search(d => d.Index(index).Query(q => q.MatchPhrase(m => m + expectedResponse = await Client.SearchAsync(d => d.Index(index).Query(q => q.MatchPhrase(m => m .Field(f => f.Field3) .Query("hey now") ))); @@ -604,10 +605,10 @@ await Client.IndexManyAsync([ Assert.Equal(expectedResponse.Total, actualResponse.Total); result = await processor.BuildQueryAsync("field3:hey*", new ElasticQueryVisitorContext().UseSearchMode()); - actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - expectedResponse = Client.Search(d => d.Index(index).Query(q => q.QueryString(m => m + expectedResponse = await Client.SearchAsync(d => d.Index(index).Query(q => q.QueryString(m => m .AllowLeadingWildcard(false) .AnalyzeWildcard(true) .Fields(f => f.Field(f1 => f1.Field3)) @@ -634,11 +635,11 @@ await Client.IndexManyAsync([ var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log)); var result = await processor.BuildQueryAsync("field1:value1 AND -field2:value2", new ElasticQueryVisitorContext().UseSearchMode()); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d + var expectedResponse = await Client.SearchAsync(d => d .Index(index).Query(f => f.Term(m => m.Field1, "value1") && !f.Term(m => m.Field2, "value2"))); string expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); @@ -649,11 +650,11 @@ await Client.IndexManyAsync([ processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log)); result = await processor.BuildQueryAsync("field1:value1 AND NOT field2:value2", new ElasticQueryVisitorContext().UseSearchMode()); - actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - expectedResponse = Client.Search(d => d + expectedResponse = await Client.SearchAsync(d => d .Index(index).Query(f => f.Term(m => m.Field1, "value1") && !f.Term(m => m.Field2, "value2"))); expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); @@ -664,11 +665,11 @@ await Client.IndexManyAsync([ processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log)); result = await processor.BuildQueryAsync("field1:value1 OR NOT field2:value2", new ElasticQueryVisitorContext().UseSearchMode()); - actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - expectedResponse = Client.Search(d => d + expectedResponse = await Client.SearchAsync(d => d .Index(index).Query(f => f.Term(m => m.Field1, "value1") || !f.Term(m => m.Field2, "value2"))); expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); @@ -679,11 +680,11 @@ await Client.IndexManyAsync([ processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log)); result = await processor.BuildQueryAsync("field1:value1 OR -field2:value2", new ElasticQueryVisitorContext().UseSearchMode()); - actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - expectedResponse = Client.Search(d => d + expectedResponse = await Client.SearchAsync(d => d .Index(index).Query(f => f.Term(m => m.Field1, "value1") || !f.Term(m => m.Field2, "value2"))); expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); @@ -707,11 +708,11 @@ await Client.IndexManyAsync([ var result = await processor.BuildQueryAsync("field1:value1 (field2:value2 OR field3:value3)", new ElasticQueryVisitorContext().UseSearchMode()); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index) + var expectedResponse = await Client.SearchAsync(d => d.Index(index) .Query(f => f.Term(m => m.Field1, "value1") || (f.Term(m => m.Field2, "value2") || f.Term(m => m.Field3, "value3")))); string expectedRequest = expectedResponse.GetRequest(); @@ -735,12 +736,12 @@ await Client.IndexManyAsync([ var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log)); var result = await processor.BuildQueryAsync("field1:value1 (field2:value2 OR field3:value3)"); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); var expectedResponse = - Client.Search(d => d.Index(index) + await Client.SearchAsync(d => d.Index(index) .Query(q => q.Bool(b => b.Filter(f => f .Term(m => m.Field1, "value1") && (f.Term(m => m.Field2, "value2") || f.Term(m => m.Field3, "value3")))))); @@ -759,11 +760,11 @@ public async Task MixedCaseTermFilterQueryProcessor() var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log)); var result = await processor.BuildQueryAsync("field1:Testing.Casing", new ElasticQueryVisitorContext { UseScoring = true }); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Query(f => f.Term(m => m.Field1, "Testing.Casing"))); + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Query(f => f.Term(m => m.Field1, "Testing.Casing"))); string expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); @@ -779,11 +780,11 @@ public async Task MultipleWordsTermFilterQueryProcessor() var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log)); var result = await processor.BuildQueryAsync("field1:\"Blake Niemyjski\"", new ElasticQueryVisitorContext { UseScoring = true }); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Query(f => f.Term(p => p.Field1, "Blake Niemyjski"))); + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Query(f => f.Term(p => p.Field1, "Blake Niemyjski"))); string expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); @@ -799,11 +800,11 @@ public async Task CanTranslateTermQueryProcessor() var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).AddVisitor(new UpdateFixedTermFieldToDateFixedExistsQueryVisitor())); var result = await processor.BuildQueryAsync("fixed:true"); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d + var expectedResponse = await Client.SearchAsync(d => d .Index(index).Query(f => f.Bool(b => b.Filter(filter => filter.Exists(m => m.Field("date_fixed")))))); string expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); @@ -827,11 +828,11 @@ await Client.IndexManyAsync([ var result = await processor.BuildQueryAsync("field1:value1 (field2:value2 OR field3:value3)", new ElasticQueryVisitorContext().SetDefaultOperator(Operator.And).UseScoring()); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index) + var expectedResponse = await Client.SearchAsync(d => d.Index(index) .Query(f => f.Term(m => m.Field1, "value1") && (f.Term(m => m.Field2, "value2") || f.Term(m => m.Field3, "value3")))); string expectedRequest = expectedResponse.GetRequest(); @@ -871,11 +872,11 @@ await Client.IndexManyAsync([ var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseFieldMap(new FieldMap { { "blah", "nested" } }).UseMappings(Client).UseNested()); var result = await processor.BuildQueryAsync("field1:value1 blah:(blah.field1:value1)", new ElasticQueryVisitorContext().UseScoring()); - var actualResponse = Client.Search(d => d.Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d + var expectedResponse = await Client.SearchAsync(d => d .Query(q => q.Match(m => m.Field(e => e.Field1).Query("value1")) && q.Nested(n => n .Path(p => p.Nested) @@ -892,11 +893,11 @@ await Client.IndexManyAsync([ result = await processor.BuildQueryAsync("field1:value1 blah:(blah.field1:value1 blah.field4:4)", new ElasticQueryVisitorContext().UseScoring()); - actualResponse = Client.Search(d => d.Query(_ => result)); + actualResponse = await Client.SearchAsync(d => d.Query(_ => result)); actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - expectedResponse = Client.Search(d => d + expectedResponse = await Client.SearchAsync(d => d .Query(q => q.Match(m => m.Field(e => e.Field1).Query("value1")) && q.Nested(n => n .Path(p => p.Nested) @@ -945,11 +946,11 @@ await Client.IndexManyAsync([ var result = await processor.BuildQueryAsync("field1:value1 nested:(nested.field1:value1 nested.field4:4 nested.field3:value3)", new ElasticQueryVisitorContext { UseScoring = true }); - var actualResponse = Client.Search(d => d.Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Query(q => q.Match(m => m.Field(e => e.Field1).Query("value1")) + var expectedResponse = await Client.SearchAsync(d => d.Query(q => q.Match(m => m.Field(e => e.Field1).Query("value1")) && q.Nested(n => n.Path(p => p.Nested).Query(q2 => q2.Match(m => m.Field("nested.field1").Query("value1")) && q2.Term("nested.field4", "4") @@ -973,11 +974,11 @@ public async Task CanGenerateMatchQuery() var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index)); var result = await processor.BuildQueryAsync("field1:test", new ElasticQueryVisitorContext().UseScoring()); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Query(q => q.Match(m => m.Field(e => e.Field1).Query("test")))); + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Query(q => q.Match(m => m.Field(e => e.Field1).Query("test")))); string expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); @@ -996,11 +997,11 @@ public async Task CanBuildAliasQueryProcessor() var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log)); var result = await processor.BuildQueryAsync("browser.version:1", new ElasticQueryVisitorContext().UseScoring()); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Query(q => q.Term(m => m.Field("browser.version").Value("1")))); + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Query(q => q.Term(m => m.Field("browser.version").Value("1")))); string expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); @@ -1018,11 +1019,11 @@ public async Task NonAnalyzedPrefixQuery() var processor = new ElasticQueryParser(c => c.UseMappings(Client, index)); var result = await processor.BuildQueryAsync("field1:value*", new ElasticQueryVisitorContext().UseSearchMode()); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualResponse); - var expectedResponse = Client.Search(d => d + var expectedResponse = await Client.SearchAsync(d => d .Index(index) .Query(f => f.Prefix(m => m.Field(f2 => f2.Field1).Value("value")))); @@ -1047,12 +1048,12 @@ public async Task RangeQueryProcessor() await processor.BuildQueryAsync("field4:[1 TO 2} OR field1:value1", new ElasticQueryVisitorContext { UseScoring = true }); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); var expectedResponse = - Client.Search( + await Client.SearchAsync( d => d.Index(index) .Query( @@ -1081,11 +1082,11 @@ public async Task DateRangeWithWildcardMinQueryProcessor() var result = await processor.BuildQueryAsync("field5:[* TO 2017-01-31} OR field1:value1", ctx); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualResponse); - var expectedResponse = Client.Search(d => d + var expectedResponse = await Client.SearchAsync(d => d .Index(index) .Query(f => f .DateRange(m => m.Field(f2 => f2.Field5).LessThan("2017-01-31").TimeZone("America/Chicago")) @@ -1113,11 +1114,11 @@ public async Task DateRangeWithDateMathQueryProcessor() var result = await processor.BuildQueryAsync("field5:[now-1d/d TO now/d]", ctx); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualResponse); - var expectedResponse = Client.Search(d => d + var expectedResponse = await Client.SearchAsync(d => d .Index(index) .Query(f => f.DateRange(m => m.Field(f2 => f2.Field5).GreaterThanOrEquals("now-1d/d").LessThanOrEquals("now/d").TimeZone("America/Chicago")))); @@ -1143,11 +1144,11 @@ public async Task DateRangeWithWildcardMaxQueryProcessor() var result = await processor.BuildQueryAsync("field5:[2017-01-31 TO * } OR field1:value1", ctx); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualResponse); - var expectedResponse = await Client.SearchAsync(d => d + var expectedResponse = await Client.SearchAsyncAsync(d => d .Index(index) .Query(f => f .DateRange(m => m.Field(f2 => f2.Field5).GreaterThanOrEquals("2017-01-31").TimeZone("America/Chicago")) @@ -1174,11 +1175,11 @@ public async Task DateRangeWithTimeZone() var result = await processor.BuildQueryAsync("field5:[2017-01-31 TO * }^\"America/Chicago\" OR field1:value1", ctx); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualResponse); - var expectedResponse = Client.Search(d => d + var expectedResponse = await Client.SearchAsync(d => d .Index(index) .Query(f => f .DateRange(m => m.Field(f2 => f2.Field5).GreaterThanOrEquals("2017-01-31").TimeZone("America/Chicago")) @@ -1204,12 +1205,12 @@ public async Task DateRangeQueryProcessor() var processor = new ElasticQueryParser(c => c.UseMappings(Client, index).SetLoggerFactory(Log)); var result = await processor.BuildQueryAsync("field5:[2017-01-01T00\\:00\\:00Z TO 2017-01-31} OR field1:value1", ctx); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); var expectedResponse = - Client.Search(d => d + await Client.SearchAsync(d => d .Index(index) .Query(f => f .DateRange(m => m @@ -1239,11 +1240,11 @@ public async Task SimpleGeoRangeQuery() await processor.BuildQueryAsync("field3:[51.5032520,-0.1278990 TO 51.5032520,-0.1278990]", new ElasticQueryVisitorContext { UseScoring = true }); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index).Query(q => + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Query(q => q.GeoBoundingBox( m => m.Field(p => p.Field3).BoundingBox("51.5032520,-0.1278990", "51.5032520,-0.1278990")))); string expectedRequest = expectedResponse.GetRequest(); @@ -1302,13 +1303,13 @@ public async Task CanSortByUnmappedField() var processor = new ElasticQueryParser(c => c.UseMappings(Client, index)); var sort = await processor.BuildSortAsync("-field1"); - var actualResponse = Client.Search(d => d.Index(index).Sort(sort)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Sort(sort)); - Assert.True(actualResponse.IsValid); + Assert.True(actualResponse.IsValidResponse); string actualRequest = actualResponse.GetRequest(true); _logger.LogInformation("Actual: {Request}", actualResponse); - var expectedResponse = Client.Search(d => d.Index(index) + var expectedResponse = await Client.SearchAsync(d => d.Index(index) .Sort( s => s.Field(f => f.Field(new Field("field1")).Descending().UnmappedType(FieldType.Keyword)) )); @@ -1338,11 +1339,11 @@ public async Task CanParseSort() .UseFieldMap(aliasMap)); var sort = await processor.BuildSortAsync("geo -field1 -(field2 field3 +field4) (field5 field3)"); - var actualResponse = Client.Search(d => d.Index(index).Sort(sort)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Sort(sort)); string actualRequest = actualResponse.GetRequest(true); _logger.LogInformation("Actual: {Request}", actualResponse); - var expectedResponse = Client.Search(d => d.Index(index).Sort(s => s + var expectedResponse = await Client.SearchAsync(d => d.Index(index).Sort(s => s .Field(f => f.Field(new Field("field3")).Ascending().UnmappedType(FieldType.GeoPoint)) .Field(f => f.Field(new Field("field1.keyword")).Descending().UnmappedType(FieldType.Keyword)) .Field(f => f.Field(new Field("field2.sort")).Descending().UnmappedType(FieldType.Keyword)) @@ -1390,10 +1391,10 @@ await Client.IndexManyAsync([ var sort = await processor.BuildSortAsync("nested.data.spaced\\ field"); var query = await processor.BuildQueryAsync("nested.data.spaced\\ field:hey"); var aggs = await processor.BuildAggregationsAsync("terms:nested.data.spaced\\ field"); - var actualResponse = Client.Search(d => d.Index(index).Sort(sort).Query(_ => query).Aggregations(_ => aggs)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Sort(sort).Query(_ => query).Aggregations(_ => aggs)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index) + var expectedResponse = await Client.SearchAsync(d => d.Index(index) .Sort(s => s .Field(f => f.Field("nested.data.spaced field.keyword").UnmappedType(FieldType.Keyword).Ascending())) .Query(q => q.Bool(b => b.Filter(f => f @@ -1417,10 +1418,10 @@ public async Task CanParseMixedCaseSort() await Client.Indices.RefreshAsync(index); var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseMappings(Client, index)); var sort = await processor.BuildSortAsync("multiWord -multiword"); - var actualResponse = Client.Search(d => d.Index(index).Sort(sort)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Sort(sort)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index(index) + var expectedResponse = await Client.SearchAsync(d => d.Index(index) .Sort(s => s .Field(f => f.Field("multiWord.keyword").UnmappedType(FieldType.Keyword).Ascending()) .Field(f => f.Field("multiWord.keyword").UnmappedType(FieldType.Keyword).Descending()) @@ -1453,11 +1454,11 @@ public async Task GeoRangeQueryProcessor() var result = await processor.BuildQueryAsync("geo:[51.5032520,-0.1278990 TO 51.5032520,-0.1278990] OR field1:value1 OR field2:[1 TO 4] OR -geo:\"Dallas, TX\"~75mi", new ElasticQueryVisitorContext { UseScoring = true }); var sort = await processor.BuildSortAsync("geo -field1"); - var actualResponse = Client.Search(d => d.Index(index).Query(_ => result).Sort(sort)); + var actualResponse = await Client.SearchAsync(d => d.Index(index).Query(_ => result).Sort(sort)); string actualRequest = actualResponse.GetRequest(true); _logger.LogInformation("Actual: {Request}", actualResponse); - var expectedResponse = Client.Search(d => d.Index(index) + var expectedResponse = await Client.SearchAsync(d => d.Index(index) .Sort(s => s .Field(f => f.Field(new Field("field3")).Ascending().UnmappedType(FieldType.GeoPoint)) .Field(f => f.Field(new Field("field1.keyword")).Descending().UnmappedType(FieldType.Keyword)) @@ -1482,11 +1483,11 @@ public async Task CanExpandElasticIncludesAsync() var processor = new ElasticQueryParser(c => c.SetLoggerFactory(Log).UseIncludes(GetIncludeAsync).UseFieldMap(aliases)); var result = await processor.BuildQueryAsync("@include:other"); - var actualResponse = Client.Search(d => d.Index("stuff").Query(_ => result)); + var actualResponse = await Client.SearchAsync(d => d.Index("stuff").Query(_ => result)); string actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); - var expectedResponse = Client.Search(d => d.Index("stuff").Query(f => f.Bool(b => b.Filter(f1 => f1.Term("aliasedincluded", "value"))))); + var expectedResponse = await Client.SearchAsync(d => d.Index("stuff").Query(f => f.Bool(b => b.Filter(f1 => f1.Term("aliasedincluded", "value"))))); string expectedRequest = expectedResponse.GetRequest(); _logger.LogInformation("Expected: {Request}", expectedRequest); @@ -1494,7 +1495,7 @@ public async Task CanExpandElasticIncludesAsync() Assert.Equal(expectedResponse.Total, actualResponse.Total); result = await processor.BuildQueryAsync("@include:other"); - actualResponse = Client.Search(d => d.Index("stuff").Query(_ => result)); + actualResponse = await Client.SearchAsync(d => d.Index("stuff").Query(_ => result)); actualRequest = actualResponse.GetRequest(); _logger.LogInformation("Actual: {Request}", actualRequest); _logger.LogInformation("Expected: {Request}", expectedRequest); diff --git a/tests/Foundatio.Parsers.ElasticQueries.Tests/InvertQueryTests.cs b/tests/Foundatio.Parsers.ElasticQueries.Tests/InvertQueryTests.cs index 3447fc49..24f4cfbd 100644 --- a/tests/Foundatio.Parsers.ElasticQueries.Tests/InvertQueryTests.cs +++ b/tests/Foundatio.Parsers.ElasticQueries.Tests/InvertQueryTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Elastic.Clients.Elasticsearch; using Foundatio.Parsers.LuceneQueries; using Foundatio.Parsers.LuceneQueries.Extensions; using Foundatio.Parsers.LuceneQueries.Nodes; @@ -188,7 +189,6 @@ public override async Task InitializeAsync() } await Client.IndexManyAsync(records, indexName); - await Client.Indices.RefreshAsync(indexName); } } diff --git a/tests/Foundatio.Parsers.ElasticQueries.Tests/Utility/ElasticsearchTestBase.cs b/tests/Foundatio.Parsers.ElasticQueries.Tests/Utility/ElasticsearchTestBase.cs index 00589aa8..06805b00 100644 --- a/tests/Foundatio.Parsers.ElasticQueries.Tests/Utility/ElasticsearchTestBase.cs +++ b/tests/Foundatio.Parsers.ElasticQueries.Tests/Utility/ElasticsearchTestBase.cs @@ -30,17 +30,17 @@ public ElasticsearchTestBase(ITestOutputHelper output, T fixture) : base(output) protected ElasticsearchClient Client => _fixture.Client; - protected void CreateNamedIndex(string index, Func, TypeMapping> configureMappings = null, Func> configureIndex = null) where TModel : class + protected void CreateNamedIndex(string index, Func, TypeMapping> configureMappings = null, Func configureIndex = null) where TModel : class { _fixture.CreateNamedIndex(index, configureMappings, configureIndex); } - protected string CreateRandomIndex(Func, TypeMapping> configureMappings = null, Func> configureIndex = null) where TModel : class + protected string CreateRandomIndex(Func, TypeMapping> configureMappings = null, Func configureIndex = null) where TModel : class { return _fixture.CreateRandomIndex(configureMappings, configureIndex); } - protected CreateIndexResponse CreateIndex(IndexName index, Func configureIndex = null) + protected CreateIndexResponse CreateIndex(IndexName index, Func configureIndex = null) { return _fixture.CreateIndex(index, configureIndex); } @@ -98,49 +98,44 @@ protected ElasticsearchClient GetClient(Action conf protected virtual void ConfigureConnectionSettings(ElasticsearchClientSettings settings) { } - public void CreateNamedIndex(string index, Func, TypeMapping> configureMappings = null, Func> configureIndex = null) where T : class + public void CreateNamedIndex(string index, Func, TypeMapping> configureMappings = null, Func configureIndex = null) where T : class { - if (configureMappings == null) - configureMappings = m => m.AutoMap().Dynamic(); + configureMappings ??= m => m.AutoMap().Dynamic(); if (configureIndex == null) configureIndex = i => i.NumberOfReplicas(0).Analysis(a => a.AddSortNormalizer()); - CreateIndex(index, i => i.Settings(configureIndex).Map(configureMappings)); + CreateIndex(index, i => i.Settings(configureIndex(new IndexSettingsDescriptor())).Map(configureMappings)); Client.ElasticsearchClientSettings.DefaultIndices[typeof(T)] = index; } - public string CreateRandomIndex(Func, TypeMapping> configureMappings = null, Func> configureIndex = null) where T : class + public string CreateRandomIndex(Func, TypeMapping> configureMappings = null, Func configureIndex = null) where T : class { string index = "test_" + Guid.NewGuid().ToString("N"); - if (configureMappings == null) - configureMappings = m => m.AutoMap().Dynamic(); - if (configureIndex == null) - configureIndex = i => i.NumberOfReplicas(0).Analysis(a => a.AddSortNormalizer()); + configureMappings ??= m => m.AutoMap().Dynamic(); + configureIndex ??= i => i.NumberOfReplicas(0).Analysis(a => a.AddSortNormalizer()); - CreateIndex(index, i => i.Settings(configureIndex).Map(configureMappings)); + CreateIndex(index, i => i.Settings(configureIndex(new IndexSettingsDescriptor())).Map(configureMappings)); Client.ElasticsearchClientSettings.DefaultIndices[typeof(T)] = index; return index; } - public CreateIndexResponse CreateIndex(IndexName index, Func configureIndex = null) + public CreateIndexResponse CreateIndex(IndexName index, Func configureIndex = null) { _createdIndexes.Add(index); - if (configureIndex == null) - configureIndex = d => d.Settings(s => s.NumberOfReplicas(0)); - + configureIndex ??= d => d.Settings(s => s.NumberOfReplicas(0)); var result = Client.Indices.Create(index, configureIndex); - if (!result.IsValid) + if (!result.IsValidResponse) throw new ApplicationException($"Unable to create index {index}: " + result.DebugInformation); return result; } - protected virtual void CleanupTestIndexes(ElasticsearchClient client) + protected virtual async Task CleanupTestIndexesAsync(ElasticsearchClient client) { if (_createdIndexes.Count > 0) - client.Indices.Delete(Indices.Index(_createdIndexes)); + await client.Indices.DeleteAsync(Indices.Index(_createdIndexes)); } public virtual Task InitializeAsync() @@ -150,7 +145,6 @@ public virtual Task InitializeAsync() public virtual Task DisposeAsync() { - CleanupTestIndexes(Client); - return Task.CompletedTask; + return CleanupTestIndexesAsync(Client); } }