<?php

require_once 'includes.php';
$client = new Elasticsearch\Client();
$jsonString = file_get_contents('amazondata.json');
$documents = json_decode($jsonString, true);
$params['index'] = 'flipzon';
$params['type'] = 'docs';
$count = 0;
foreach ($documents as $document) {
    $params['body']['query']['filtered']['query']['bool']['must'] = [['match' => ['title' => $document['title']]], ['match' => ['color' => $document['color']]]];
    $params['body']['query']['filtered']['filter']['range']['internal']['gte'] = $document['internal'];
    $results = $client->search($params);
    if ($results['hits']['total'] != 0) {
        //update the document
        $count++;
        $id = $results['hits']['hits'][0]['_id'];
        $price_from_fk = $results['hits']['hits'][0]['_source']['price_from_fk'];
        unset($params['body']);
        $params['id'] = $id;
        $params['body']['doc'] = $document;
        $client->update($params);
        unset($params['body']);
        unset($params['id']);
    }
}
echo $count;
 private function reindexar_agente($id, $dados_agente)
 {
     $client_params = array('hosts' => $this->config->item('elasticsearch_hosts'));
     $client = new Elasticsearch\Client($client_params);
     $client->update(array('body' => array('doc' => array('nome_responsavel' => $dados_agente['nome_responsavel'], 'slug' => $dados_agente['slug'], 'atividades_culturais' => strip_tags_better($dados_agente['atividades_culturais']))), 'index' => 'varadouro', 'type' => 'agente_cultural', 'id' => $id));
 }
 private function reindexar_noticia($id, $dados_noticia)
 {
     $client_params = array('hosts' => $this->config->item('elasticsearch_hosts'));
     $client = new Elasticsearch\Client($client_params);
     $client->update(array('body' => array('doc' => array('data' => $dados_noticia['data'], 'titulo' => $dados_noticia['titulo'], 'slug' => $dados_noticia['slug'], 'conteudo' => strip_tags_better($dados_noticia['conteudo']))), 'index' => 'varadouro', 'type' => 'noticia', 'id' => $id));
 }