I have an object PurchaseOrder that has a List<VendorStatus> VendorStatuses, VendorStatus has an EstimatedShipDate column. I need to filter a purchase order by the latest EstimatedShipDate. How can I do this?
I've tried:
Filter<PurchaseOrder>.Range(r => r
.OnField(x => x.VendorStatuses.OrderByDescending(v => v.StatusUpdateDate).First().EstimatedShipDate)
.GreaterOrEquals(fromDate)
.LowerOrEquals(toDate));
and
var f = Filter<PurchaseOrder>.Range(r => r
.OnField("VendorStatuses.EstimatedShipDate")
.GreaterOrEquals(fromDate)
.LowerOrEquals(toDate));
and
var newFilter = Filter<PurchaseOrder>.Nested(nfd => nfd.Path(x => x.VendorStatuses.First().EstimatedShipDate))
.Filter(f2 => f2.Range(x => x.OnField(f => f.VendorStatuses.First().EstimatedShipDate)
.GreaterOrEquals(fromDate)
.LowerOrEquals(toDate))));
But none of these worked. How can I do this?
I'm not even able to get the date range working when running against elastic directly. The following query returns no results even though when using the head plugin i can see them listed under "po"
{
"query": {
"range": {
"po.vendorStatuses.estimatedShipDate": {
"gte": "2016-10-01",
"lte": "2016-11-01",
}
}
}
}
We're using Nest version 1.7.2 in our project with elastic 1.4.5.
Here's some more info on our types:
//that builds our search query, contains many methods to build up the FilterContainer
public class PurchaseOrderSearchQueryBuilder
{
protected FilterContainer Filter { get; set; }
public PurchaseOrderSearchQueryBuilder WithExpectedShipDate(DateTime fromDate, DateTime toDate)
{
var newFilter = Filter<PurchaseOrder>.
//method i need to implment
Filter &= newFilter;
return this;
}
}
//example working filter method
public PurchaseOrderSearchQueryBuilder WithCustomerId(long customerId)
{
if (customerId > 0)
Filter &= Filter && Filter<PurchaseOrder>.Term(p => p.CustomerId, customerId);
return this;
}
public class PurchaseOrder
{
...
public long CustomerId { get; set; }
public List<PoVendorStatus> VendorStatuses { get; set; }
}
public class PoVendorStatus
{
public long Id { get; set; }
...
public DateTime? EstimatedShipDate { get; set; }
public DateTime StatusUpdateDate { get; set; }
}
ElasticSearch.NetorNest? I cannot find any static classFilter<>in both Namespaces.PurchaseOrderbyEstimatedShipDateout of allPurchaseOrders? IsList<VendorStatusmapped as a nested type? Can you show the mapping in Elasticsearch forPurchaseOrder?