/**
  * Setup 
  *
  * @since 0.1
  */
 public function setUp()
 {
     parent::setUp();
     $param = array();
     $param['endpoint'] = ES_HOST;
     $param['port'] = ES_PORT;
     $param['index'] = 'wordpress';
     $param['type'] = 'blog';
     add_option('wpels_settings', $param);
     $this->client = WP_Elasticsearch::get_instance();
 }
Ejemplo n.º 2
0
    }
    /**
     * Create connection to Elasticsearch
     *
     * @param $options
     * @return Client client object
     * @since 0.1
     */
    private function _create_client($options)
    {
        if (empty($options['endpoint']) || empty($options['port']) || empty($options['index']) || empty($options['type'])) {
            return false;
        }
        $es_options = array('host' => $options['endpoint'], 'port' => $options['port']);
        if (isset($options['aws_auth']) && $options['aws_auth'] === 'true') {
            $es_options['persistent'] = false;
            $es_options['transport'] = 'AwsAuthV4';
            if (!empty($options['access_key']) && !empty($options['secret_key'])) {
                $es_options['aws_access_key_id'] = $options['access_key'];
                $es_options['aws_secret_access_key'] = $options['secret_key'];
            }
            if (!empty($options['region'])) {
                $es_options['aws_region'] = $options['region'];
            }
        }
        $client = new \Elastica\Client($es_options);
        return $client;
    }
}
WP_Elasticsearch::get_instance()->init();