Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 弹性搜索。数据更新和保存字段以前值的历史记录_Php_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Php,elasticsearch" /> elasticsearch,Php,elasticsearch" />

Php 弹性搜索。数据更新和保存字段以前值的历史记录

Php 弹性搜索。数据更新和保存字段以前值的历史记录,php,elasticsearch,Php,elasticsearch,我的映射的一部分是: "current_price" => ["type" => "float"], "price_history" => [ "type" => "nested", "properties" => [ "date" => ["type" => "date"], "value" => ["type" => "float"] ] 正如你所见,我保存了

我的映射的一部分是:

"current_price"         => ["type" => "float"],
"price_history"         => [
    "type"       => "nested",
    "properties" => [
    "date"  => ["type" => "date"],
    "value" => ["type" => "float"]
]
正如你所见,我保存了货物的当前价格和所有以前的价值。我想注意的第一件事是,当我第一次创造商品时,我当然没有历史。这就是为什么当我创建商品时,我根本不使用price_历史,尽管它存在于我的映射中

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

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

    ]
];
当我编辑商品时,我会更改价格。在这种情况下,我需要将当前价格移动到存档,将其移动到price_history字段。然后我需要替换当前名称。问题是关于价格历史领域。我得到以前的值($goods[''u source']['price\u history']),然后将当前的\u名称添加到此数组中。我已经有了一些历史,一切都很好。但如果我没有,那么我会得到错误“未定义索引:价格历史”。在这种情况下,我应该进行检查:if(isset($goods[''u source']['price\u history'])。这正常吗?在关系数据库中,我会有一个空数组,但在Elasticsearch中,我没有,而且我必须进行数组级(也就是说)检查。如何处理这些案件?当我创建商品时,我是否应该在价格历史记录中添加一个epmty数组