Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the get-index-settings WP-CLI command #3547

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions includes/classes/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -1565,4 +1565,29 @@ public function delete_search_template() {
$instant_results->epio_delete_search_template();
WP_CLI::success( esc_html__( 'Done.', 'elasticpress' ) );
}

/**
* Get an index settings
*
* ## OPTIONS
*
* <index_name>
* : Index name
*
* [--pretty]
* : Use this flag to render a pretty-printed version of the JSON response.
*
* @subcommand get-index-settings
*
* @since 4.7.0
*
* @param array $args Positional CLI args.
* @param array $assoc_args Associative CLI args.
*/
public function get_index_settings( $args, $assoc_args ) {
$response = Elasticsearch::factory()->get_index_settings( $args[0] );
$pretty = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pretty' );

$this->pretty_json_encode( $response, $pretty );
}
}
25 changes: 25 additions & 0 deletions tests/php/TestCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,31 @@ public function testThrowsErrorWhenHostIsNotSet() {
$this->command->sync( [], [] );
}

/**
* Test get-index-settings command returns an index settings.
*
* @since 4.7.0
*/
public function testGetIndexSettings() {
$this->command->get_index_settings( [ 'exampleorg-post-1' ], [] );

$output = $this->getActualOutputForAssertion();
$this->assertStringStartsWith( '{', $output );
$this->assertStringContainsString( 'index.mapping.total_fields.limit', $output );

// clean output buffer
ob_clean();

// test with --pretty flag
$this->command->get_index_settings( [ 'exampleorg-post-1' ], [ 'pretty' => true ] );

$output = $this->getActualOutputForAssertion();
$this->assertStringStartsWith( "{\n", $output );

// clean output buffer
ob_clean();
}

/**
* Test commands throws an error if indexing is already happening.
*/
Expand Down