public void Properly_filters_numeric_ranges(string yearRange, int expectedResults) { var elasticClient = fixture.GetElasticClient(); var indexName = fixture.GetRandomIndexName("vehicles"); var camaro = new Car { Name = "Camaro", Year = 2020 }; var corvette = new Car { Name = "Corvette", Year = 2010 }; var monteCarlo = new Car { Name = "Monte Carlo", Year = 2000 }; elasticClient.Index(camaro, x => x.Index(indexName)); elasticClient.Index(corvette, x => x.Index(indexName)); elasticClient.Index(monteCarlo, x => x.Index(indexName)); elasticClient.Refresh(indexName); var noResults = elasticClient.Search <Car>(s => s.Index(indexName).Query( q => q.Bool(x => x.Filter(new { Year = Range.FromString <int>(yearRange) })))); Assert.Equal(expectedResults, noResults.Hits.Count()); }
public void Properly_filters_date_ranges(string startProductionRunRange, int expectedResults) { var elasticClient = fixture.GetElasticClient(); var indexName = fixture.GetRandomIndexName("vehicles"); var camaro = new Car { Name = "Camaro", StartProductionRun = DateTimeOffset.Parse("2020-01-01T00:00:00Z") }; var corvette = new Car { Name = "Corvette", StartProductionRun = DateTimeOffset.Parse("2010-01-01T00:00:00Z") }; var monteCarlo = new Car { Name = "Monte Carlo", StartProductionRun = DateTimeOffset.Parse("2000-01-01T00:00:00Z") }; elasticClient.Index(camaro, x => x.Index(indexName)); elasticClient.Index(corvette, x => x.Index(indexName)); elasticClient.Index(monteCarlo, x => x.Index(indexName)); elasticClient.Refresh(indexName); var noResults = elasticClient.Search <Car>(s => s.Index(indexName).Query( q => q.Bool(x => x.Filter(new { StartProductionRun = Range.FromString <DateTime>(startProductionRunRange) })))); Assert.Equal(expectedResults, noResults.Hits.Count()); }