Skip to content

Removed the product check for client API < 8 #231

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

Merged
merged 3 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions lib/Search/Elasticsearch.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use Search::Elasticsearch::Util qw(parse_params load_plugin);
use namespace::clean;

our $VERSION = '8.00';
our $API_VERSION; # Major version of client API

my %Default_Plugins = (
client => [ 'Search::Elasticsearch::Client', '8_0::Direct' ],
Expand Down Expand Up @@ -64,6 +65,9 @@ sub new {
$plugin_class->_init_plugin($params);
}

# Get major version of client API
$Search::Elasticsearch::API_VERSION = substr($params->{client}->{api_version}, 0, index($params->{client}->{api_version}, '_'));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of a global variable for this seems suboptimal, as it's an attribute specific to the client being used for this object. This would get overwritten every time a different version of the client is constructed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, even if this apply only if you have multiple instances of the client. I need to find a way to access the API version of the client from process_response() in Search::Elasticsearch::Role::Cxn. I'm looking into it.


return $params->{client};
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Search/Elasticsearch/Role/Cxn.pm
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ sub process_response {
#===================================
my ( $self, $params, $code, $msg, $body, $headers ) = @_;

# Product check
if ( $code >= 200 and $code < 300 ) {
# Product check only for 8+ client API version
if ( $Search::Elasticsearch::API_VERSION >= 8 and $code >= 200 and $code < 300 ) {
my $product = $headers->{$PRODUCT_CHECK_HEADER} // '';
if ($product ne $PRODUCT_CHECK_VALUE) {
throw( "ProductCheck", "The client noticed that the server is not Elasticsearch and we do not support this unknown product" );
Expand Down