Skip to content

Commit

Permalink
Merge pull request #3126 from rebeccahum/add/get_index_settings
Browse files Browse the repository at this point in the history
Add get_index_settings()
  • Loading branch information
felipeelia authored Nov 8, 2022
2 parents d23630f + ba9ecda commit 935e608
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions includes/classes/Elasticsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,28 @@ public function open_index( $index ) {
return ( ! is_wp_error( $request ) && 200 === wp_remote_retrieve_response_code( $request ) );
}

/**
* Get index settings.
*
* @param string $index Index name.
* @since 4.4.0
* @return array|WP_Error Raw ES response from the $index/_settings?flat_settings=true endpoint
*/
public function get_index_settings( string $index ) {
$endpoint = trailingslashit( $index ) . '_settings?flat_settings=true';
$request = $this->remote_request( $endpoint, [], [], 'get_index_settings' );

if ( is_wp_error( $request ) ) {
return $request;
}

$response_body = wp_remote_retrieve_body( $request );

$settings = json_decode( $response_body, true );

return $settings;
}

/**
* Update index settings.
*
Expand Down

0 comments on commit 935e608

Please sign in to comment.