/**
  * Create the network alias from an array of indexes
  *
  * @param array $indexes
  * @since 0.9.0
  * @return array|bool
  */
 public function create_network_alias($indexes)
 {
     $url = untrailingslashit(EP_HOST) . '/_aliases';
     $args = array('actions' => array());
     foreach ($indexes as $index) {
         $args['actions'][] = array('add' => array('index' => $index, 'alias' => ep_get_network_alias()));
     }
     $request_args = array('body' => json_encode($args), 'method' => 'POST', 'headers' => $this->format_request_headers());
     $request = wp_remote_request($url, apply_filters('ep_create_network_alias_request_args', $request_args, $args, $indexes));
     if (!is_wp_error($request) && (200 >= wp_remote_retrieve_response_code($request) && 300 > wp_remote_retrieve_response_code($request))) {
         $response_body = wp_remote_retrieve_body($request);
         return json_decode($response_body);
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * Retrieves search stats from Elasticsearch.
  *
  * Retrieves various search statistics from the ES server.
  *
  * @since 1.9
  *
  * @param int $blog_id Id of blog to get stats.
  *
  * @return array Contains the status message or the returned statistics.
  */
 public function get_search_status($blog_id = null)
 {
     if (is_wp_error(ep_get_host())) {
         return array('status' => false, 'msg' => esc_html__('Elasticsearch Host is not available.', 'elasticpress'));
     } else {
         if (is_multisite() && null === $blog_id) {
             $path = ep_get_network_alias() . '/_stats/search/';
         } else {
             $path = ep_get_index_name($blog_id) . '/_stats/search/';
         }
         $request = ep_remote_request($path, array('method' => 'GET'));
     }
     if (!is_wp_error($request)) {
         $stats = json_decode(wp_remote_retrieve_body($request));
         if (isset($stats->_all)) {
             return $stats->_all->primaries->search;
         }
         return false;
     }
     return array('status' => false, 'msg' => $request->get_error_message());
 }
Exemplo n.º 3
0
 /**
  * Create the network alias from an array of indexes
  *
  * @param array $indexes
  * @since 0.9.0
  * @return array|bool
  */
 public function create_network_alias($indexes)
 {
     $path = '_aliases';
     $args = array('actions' => array());
     foreach ($indexes as $index) {
         $args['actions'][] = array('add' => array('index' => $index, 'alias' => ep_get_network_alias()));
     }
     $request_args = array('body' => json_encode($args), 'method' => 'POST');
     $request = ep_remote_request($path, apply_filters('ep_create_network_alias_request_args', $request_args, $args, $indexes));
     if (!is_wp_error($request) && (200 >= wp_remote_retrieve_response_code($request) && 300 > wp_remote_retrieve_response_code($request))) {
         $response_body = wp_remote_retrieve_body($request);
         return json_decode($response_body);
     }
     return false;
 }
Exemplo n.º 4
0
 /**
  * Determine the index variable to be passed to ep_get_index_url.
  *
  * @param string $scope
  * @since 1.1.1
  * @return mixed
  */
 private function _get_index($scope = 'current')
 {
     $index = null;
     if ('all' === $scope) {
         $index = ep_get_network_alias();
     } elseif (is_int($scope)) {
         $index = ep_get_index_name($scope);
     } elseif (is_array($scope)) {
         $index = array();
         foreach ($scope as $site_id) {
             $index[] = ep_get_index_name($site_id);
         }
     }
     return $index;
 }