我正在尝试编写一个弹性搜索查询,该查询从订单和销售中获得最新的前100名,但我的问题是订单有shipping_date。我想对订单使用“shipment_date”,对销售进行“created_date”以对它们进行排序。我找不到办法做到这一点,有一些解决方案与脚本,但他们不适合我可能因为我使用elasticsearch版本6.谢谢
var response = client.Search<DataModel>(x =>
x.Index("order*,sale*").Type("")
.Query(q =>
q.Term(t => t.customerID, customerID) &&
q.DateRange(d => d
.Field(f => f.created_date)
.GreaterThanOrEquals(fromDate)
.LessThanOrEquals(toDate)
)
)
.From(0)
.Size(100)
.Sort(s => s.Field(f => f
.Field("created_date")
.Order(SortOrder.Descending)
))
);
示例文件:
订单:
"order_id": "8796",
"item_id": "69813",
"price": 50.25,
"quantity": 1,
"status": 3,
"shipment_date": "2018-01-04T16:01:24Z",
"order_date": "2018-01-03T21:19:04Z"
出售:
"sale_id": "4032",
"order_id": "8796",
"created_date": "2018-01-09T18:23:11Z"