У меня есть объект типа:
"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"
//...
}
}