dongweishi2028 2016-02-27 15:58
浏览 639

Elasticsearch。 数据更新和保留以前字段值的历史记录

Part of my mapping is:

"current_price"         => ["type" => "float"],
"price_history"         => [
    "type"       => "nested",
    "properties" => [
    "date"  => ["type" => "date"],
    "value" => ["type" => "float"]
]

As you can see I keep in storage current price of goods and all the previous values. First thing I would like to notice is when I create goods in a very first time, I have no history, of course. That's why when I create goods, I do not use price_history at all, although it exists in my mapping.

$params = [
    'index' => config('storesettings.esIndex'),
    'type'  => config('storesettings.esType'),
    'id'    => $id,
    'body'  => [

        ... 
        "current_price"         => $request->get('current_price'),
        ...

    ]
];

When I edit goods, I change the price. In this case I need to move the current price to archive, moving it to price_history field. And then I need to replace current name. The question is about price_history field. I get previous value ($goods['_source']['price_history']) then I add to this array current_name. Everything is fine when I already have some history. But if I have not, then I get the error 'Undefined index: price_history'. In this case I should do checking: if(isset($goods['_source']['price_history'])). Is it normal? In relational databases I would have an empty array, but in Elasticsearch I haven't and I must do array level (so to speak) checking. How to handle such cases? Maby I should add an epmty array to price_history when I create goods?..

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?