public static void CustomTypes_Terms() { var context = new TestableElasticContext(); var identifiers = new[] { new Identifier("vALue1"), new Identifier("ValuE2") }; var queryInfo = context.Query<ClassWithIdentifier>().Where(x => identifiers.Contains(x.id)).ToQueryInfo(); // Also verifies that any value which gets JSON converted into a string gets lower-cased Assert.Equal(@"{""query"":{""filtered"":{""filter"":{""terms"":{""id"":[""value1!!"",""value2!!""]}}}}}", queryInfo.Query); }
public void OrOperatorGeneratesFlattenedOrCriteria() { var possibleIds = new[] { 1, 2, 3, 4 }; var where = Robots.Where(e => e.Name == "IG-88" || e.Cost > 1 || e.Zone.HasValue || possibleIds.Contains(e.Id)); var criteria = ElasticQueryTranslator.Translate(Mapping, where.Expression).SearchRequest.Filter; var orCriteria = Assert.IsType<OrCriteria>(criteria); Assert.Equal("or", orCriteria.Name); Assert.Single(orCriteria.Criteria, f => f.Name == "term"); Assert.Single(orCriteria.Criteria, f => f.Name == "range"); Assert.Single(orCriteria.Criteria, f => f.Name == "exists"); Assert.Single(orCriteria.Criteria, f => f.Name == "terms"); Assert.Equal(4, orCriteria.Criteria.Count); }
public void DateTimeArrayContainsGeneratesTermsCriteria() { var expectedIds = new[] { 1, 3, 2, 9, 7, 6, 123, 4568 }.Select(d => DateTime.Now.AddDays(d)).ToArray(); var where = Robots.Where(e => expectedIds.Contains(e.Started)); var criteria = ElasticQueryTranslator.Translate(Mapping, where.Expression).SearchRequest.Filter; var termsCriteria = Assert.IsType<TermsCriteria>(criteria); Assert.Equal("terms", termsCriteria.Name); Assert.Equal("started", termsCriteria.Field); Assert.Equal(expectedIds.Length, termsCriteria.Values.Count); foreach (var term in expectedIds) Assert.Contains(term, termsCriteria.Values); }
public void Int32ArrayContainsGeneratesTermsCriteria() { var expectedIds = new[] { 1, 3, 2, 9, 7, 6, 123, 45678 }; var where = Robots.Where(e => expectedIds.Contains(e.Id)); var criteria = ElasticQueryTranslator.Translate(Mapping, where.Expression).SearchRequest.Filter; var termsCriteria = Assert.IsType<TermsCriteria>(criteria); Assert.Equal("id", termsCriteria.Field); Assert.Equal(expectedIds.Length, termsCriteria.Values.Count); foreach (var term in expectedIds) Assert.Contains(term, termsCriteria.Values); }
public void DoubleArrayContainsGeneratesTermsCriteria() { var expectedValues = new[] { 1.1, 3.2, 4.9, 7.6, 8.9, 12345.678 }; var where = Robots.Where(e => expectedValues.Contains(e.EnergyUse)); var criteria = ElasticQueryTranslator.Translate(Mapping, where.Expression).SearchRequest.Filter; var termsCriteria = Assert.IsType<TermsCriteria>(criteria); Assert.Equal("energyUse", termsCriteria.Field); Assert.Equal(expectedValues.Length, termsCriteria.Values.Count); foreach (var term in expectedValues) Assert.Contains(term, termsCriteria.Values); }
public void DecimalArrayContainsGeneratesTermsCriteria() { var expectedHourlyWages = new[] { 1.1m, 3.2m, 4.9m, 7.6m, 8.9m, 12345.678m }; var where = Robots.Where(e => expectedHourlyWages.Contains(e.Cost)); var criteria = ElasticQueryTranslator.Translate(Mapping, where.Expression).SearchRequest.Filter; var termsCriteria = Assert.IsType<TermsCriteria>(criteria); Assert.Equal("cost", termsCriteria.Field); Assert.Equal(expectedHourlyWages.Length, termsCriteria.Values.Count); foreach (var term in expectedHourlyWages) Assert.Contains(term, termsCriteria.Values); }
public void StringArrayExistingContainsWithNullGeneratesOrWithTermsAndMissingCriteria() { const string expectedField = "name"; var names = new[] { "Robbie", null, "IG-88", "Marvin" }; var where = Robots.Where(e => names.Contains(e.Name)); var criteria = ElasticQueryTranslator.Translate(Mapping, where.Expression).SearchRequest.Filter; var orCriteria = Assert.IsType<OrCriteria>(criteria); Assert.Equal(2, orCriteria.Criteria.Count); var missingCriteria = orCriteria.Criteria.OfType<MissingCriteria>().Single(); Assert.Equal(expectedField, missingCriteria.Field); var termsCriteria = orCriteria.Criteria.OfType<TermsCriteria>().Single(); Assert.Equal(expectedField, termsCriteria.Field); Assert.Equal(names.Length - 1, termsCriteria.Values.Count); foreach (var term in names.Where(n => n != null)) Assert.Contains(term, termsCriteria.Values); }
public void StringArrayExistingContainsGeneratesTermsCriteria() { var expectedNames = new[] { "Robbie", "Kryten", "IG-88", "Marvin" }; var where = Robots.Where(e => expectedNames.Contains(e.Name)); var criteria = ElasticQueryTranslator.Translate(Mapping, where.Expression).SearchRequest.Filter; var termsCriteria = Assert.IsType<TermsCriteria>(criteria); Assert.Equal("name", termsCriteria.Field); Assert.Equal(expectedNames.Length, termsCriteria.Values.Count); foreach (var term in expectedNames) Assert.Contains(term, termsCriteria.Values); }