您好我的弹性查询如下
sq.Query = Query<Person>
.Bool(fd => fd
.Must(must => must
.Match(m => m
.Field("first_name")
.Query(p.first_name)
.Fuzziness(Fuzziness.EditDistance(2))),
must => must
.Match(ln => ln
.Field("last_name")
.Query(p.last_name)
.Fuzziness(Fuzziness.EditDistance(2))))
.Should(should => should
.Match(m => m
.Field("father_first_name")
.Query(p.father_first_name)
.Fuzziness(Fuzziness.EditDistance(2))),
should => should.Match(m => m
.Field("father_last_name")
.Query(p.father_last_name)
.Fuzziness(Fuzziness.EditDistance(2))),
should => should.Match(m => m
.Field("mother_first_name")
.Query(p.mother_first_name)
.Fuzziness(Fuzziness.EditDistance(2))),
should => should.Match(m => m
.Field("mother_last_name")
.Query(p.mother_last_name)
.Fuzziness(Fuzziness.EditDistance(2))),
should => should.DateRange(m => m
.Field("birth_date")
.Name(p.birth_date)
.GreaterThanOrEquals(p.birth_date)
.LessThan(p.birth_date)),
should => should.DateRange(m => m
.Field("birth_year")
.Name(p.birth_year)
.GreaterThanOrEquals(p.birth_year)
.LessThan(p.birth_year)),
should => should.DateRange(m => m
.Field("death_date")
.Name(p.death_date)
.GreaterThanOrEquals(p.death_date)
.LessThan(p.death_date)),
should => should.DateRange(m => m
.Field("death_year")
.Name(p.death_year)
.GreaterThanOrEquals(p.death_year)
.LessThan(p.death_year)),
should => should.Match(m => m
.Field("death_place")
.Query(p.death_place))));
现在我想在查询中附加marriage_date,它来自动态列表,如下所示。 'marriage_date'是我需要从列表中追加到现有查询的术语
List<DateRangeQuery> lstMarriageDateQuery = new List<DateRangeQuery>();
if (p.Marriages != null)
{
foreach (var item in p.Marriages)
{
if (!string.IsNullOrEmpty((item.marriage_date)))
{
DateRangeQuery query = new DateRangeQuery();
query.Field = "marriage_date";
query.Name = item.marriage_date;
query.GreaterThanOrEqualTo = item.marriage_date;
query.LessThan = item.marriage_date;
lstMarriageDateQuery.Add(query);
}
}
}
如何将daterangequery附加到现有查询