使用 ElasticSearch 7.6 我想找到区域列表中的所有点。还有几个其他过滤条件被添加到 QueryContainerDescriptors 列表中并应用于最终搜索。
var queries = new List<Func<QueryContainerDescriptor<MySearchableObject>, QueryContainer>>();
此示例适用于一个区域,其中 Coordinates 是字典
foreach (var area in areas)
{
var pointsList = area.Coordinates.Values.Select(p => new GeoLocation(p.Latitude, p.Longitude)).ToList();
queries.Add(sqs => sqs
.GeoPolygon(r => r
.Field(f => f.Position)
.ValidationMethod(GeoValidationMethod.Strict)
.Points(pointsList)));
}
还有这个:
queries.Add(sqs => sqs.Bool(b=>b.Should(bs => GeoPolygonShouldQuery(bs, area))));
private static QueryContainer GeoPolygonShouldQuery(QueryContainerDescriptor<MySearchableObject> bs, FilterArea area)
{
return bs
.GeoPolygon(r => r
.Field(f => f.Position)
.ValidationMethod(GeoValidationMethod.Strict)
.Points(area.Coordinates.Values.Select(p => new GeoLocation(p.Latitude, p.Longitude))));
}
我将如何解决为列表中的每个区域附加一个应该子句?
与此类似:
queries.Add(sqs => sqs.Bool(b => b.Should(
bs => bs.GeoPolygon(r => r.Field(f => f.Position)
.Points(areas.ElementAt(0).Coordinates.Values.Select(p => new GeoLocation(p.Latitude, p.Longitude)).ToList())),
bs => bs.GeoPolygon(r => r.Field(f => f.Position)
.Points(areas.ElementAt(1).Coordinates.Values.Select(p => new GeoLocation(p.Latitude, p.Longitude)).ToList()))
)));