使用php在elasticsearch2中查找和更新文档

时间:2016-03-22 02:45:17

标签: php elasticsearch

我正在尝试使用ElasticSearch查找文档并更新其中的字段。代码是:

PLS-00642: local collection types not allowed in SQL statements

代码正在提供 require_once 'vendor/autoload.php'; $client = Elasticsearch\ClientBuilder::create()->build(); $params = [ 'index' => 'myIndex', 'type' => 'myCollection', 'body' => [ 'query'=> [ 'match'=> [ 'accessToken' => $accessToken ] ] , 'script' => 'ctx._source.deviceId= deviceId', 'params' => [ 'deviceId' => $deviceId ], 'upsert' => [ 'counter' => 1 ] ] ]; 。知道我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

如果你想将deviceid的值增加1(表示如果deviceid的值为4,则可以通过向其添加1将其增加到5),然后按照以下代码

 'script' => 'ctx._source.deviceId= deviceId', 
    replace with 
     'script' => 'ctx._source.counter += deviceId',

示例:

$params = [
        'index' => 'my_index',
        'type' => 'my_type',
        'id' => 'my_id',
        'body' => [
            'script' => 'ctx._source.counter += count',
            'params' => [
                'count' => 4
            ],
            'upsert' => [
                'counter' => 1
            ]
        ]
    ];

    $response = $client->update($params);

Check i Elasticsearch php