我有类似的对象
"hits": {
"total": 1,
"max_score": 1.0,
"hits": [
{
"_index": "products",
"_type": "product",
"_id": "1",
"_score": 1.0,
"_source": {
"name": "Test product",
"prices": [
{
"price": 2.36,
"timestamp": "2018-09-27T10:56:45.916945"
},
{
"price": 4.26,
"timestamp": "2018-09-24T10:56:45.916945"
},
{
"price": 1.66,
"timestamp": "2018-09-26T10:56:45.916945"
}
],
"category": "Category_1"
//...
}
}
我通过简单查询得到的信息:
{
"query" : {
"term" : {
"name" : "product"
}
}
}
我想扩展查询以获取名为latest_price
和latest_price_timestamp
的新动态字段,这些字段将包含prices
数组中总是最新条目的值。例如:
"hits": {
"total": 1,
"max_score": 1.0,
"hits": [
{
"_index": "products",
"_type": "product",
"_id": "1",
"_score": 1.0,
"_source": {
"name": "Test product",
"latest_price": 2.36",
"latest_price_timestamp": "2018-09-27T10:56:45.916945",
"prices": [
{
"price": 2.36,
"timestamp": "2018-09-27T10:56:45.916945"
},
{
"price": 4.26,
"timestamp": "2018-09-24T10:56:45.916945"
},
{
"price": 1.66,
"timestamp": "2018-09-26T10:56:45.916945"
}
],
"category": "Category_1"
//...
}
}