Update by query (updateByQuery) Elasticsearch-PHP

前端 未结 2 1229
心在旅途
心在旅途 2021-01-17 04:34

I am Using Elasticsearch 2.3 along with the official php driver. The updateByQuery is giving me troubles to use in php. A

2条回答
  •  孤街浪徒
    2021-01-17 05:29

    I want to add a small addition to the previous answer

    You may not add the following params in elasticsearch.yml

    script.engine.groovy.inline.search: on
    script.engine.groovy.inline.aggs: on
    script.engine.groovy.inline.update: on
    

    And your query will be:

    $client = \Elasticsearch\ClientBuilder::create()->setHosts(['127.0.0.1:9200'])->build();
    # Request
    $updateRequest = [
        'index'     => 'testindex',
        'type'      => 'logs',
        'conflicts' => 'proceed',
        'body' => [
            'query' => [ 
                'filtered' => [
                    'filter' => [
                        'bool' =>   [
                            'must' => [
                                [
                                    'match' => [ 'enabled' => 1 ],
                                ],
                            ]
                        ]
                    ]
                ]
            ],
            'script' => [
                'lang' => 'painless',
                'source' => 'ctx._source.enabled = params.value',
                'params' => [
                    'value' => 0
                ]
            ]
        ]
    ];
    
    # Update 
    $results = $client->updateByQuery($updateRequest);
    

提交回复
热议问题