Connection impossible to es


(Jérome) #1

Hi,

Today when i run my program appears an error, for the first time, last
week there's no error.
Error says impossible to connect. I don't understand why today and not
last week, more than i can't execute my job now because cannot
connect.


Script code :


#!/usr/bin/perl

use strict;
use warnings;

use ElasticSearch;

			my $es = ElasticSearch->new(
									        transport    =>  'http',
									        servers      =>  'localhost:9200'
										);
										    $es->cluster_health( wait_for_status => 'yellow' );

Error


[ERROR] ** ElasticSearch::Error::NoServers at /Library/Perl/5.10.0/
ElasticSearch/Transport.pm line 256 :
Could not retrieve a list of active servers:
[ERROR] ** ElasticSearch::Error::Connection at /Library/Perl/
5.10.0/ElasticSearch/Transport/HTTP.pm line 60 :
Can't connect to localhost:9200 (connect: Connection refused)
(500)

With vars:{
  'request' => {
    'qs' => {},
    'cmd' => '/_cluster/nodes',
    'method' => 'GET'
  },
  'status_code' => 500,
  'server' => 'localhost:9200',
  'status_msg' => 'Can\'t connect to localhost:9200 (connect:

Connection refused)'
}

With vars:{
'servers' => [
'localhost:9200'
]
}

Thanks


(Clinton Gormley) #2

Hi Jerome

Today when i run my program appears an error, for the first time, last
week there's no error.
Error says impossible to connect. I don't understand why today and not
last week, more than i can't execute my job now because cannot
connect.

Are you sure elasticsearch is running?

clint


Script code :


#!/usr/bin/perl

use strict;
use warnings;

use ElasticSearch;

  		my $es = ElasticSearch->new(
  								        transport    =>  'http',
  								        servers      =>  'localhost:9200'
  									);
  									    $es->cluster_health( wait_for_status => 'yellow' );

Error


[ERROR] ** ElasticSearch::Error::NoServers at /Library/Perl/5.10.0/
ElasticSearch/Transport.pm line 256 :
Could not retrieve a list of active servers:
[ERROR] ** ElasticSearch::Error::Connection at /Library/Perl/
5.10.0/ElasticSearch/Transport/HTTP.pm line 60 :
Can't connect to localhost:9200 (connect: Connection refused)
(500)

With vars:{
  'request' => {
    'qs' => {},
    'cmd' => '/_cluster/nodes',
    'method' => 'GET'
  },
  'status_code' => 500,
  'server' => 'localhost:9200',
  'status_msg' => 'Can\'t connect to localhost:9200 (connect:

Connection refused)'
}

With vars:{
'servers' => [
'localhost:9200'
]
}

Thanks


(Sushis) #3

I feel really really stupid...
Sorry for disturbing.


(Jérome) #4

I feel really really stupid...
but there's no stupid question ! (maybe yes in fact...)

As you can see i'm just starting with ES in PERL and i have an other
question :

I have an other script for indexing all data in a file. But the
error :

Can't locate object method "index" via package "type7_1" (perhaps you
forgot to load "type7_1"?) at lectureFichiers.pm line 36, line
1.

I don't understand the message someone can explain ?


(Clinton Gormley) #5

Can't locate object method "index" via package "type7_1" (perhaps you
forgot to load "type7_1"?) at lectureFichiers.pm line 36, line
1.

You don't show the code, but you are calling method 'index' on a
variable, and that variable contains the value 'type7_1', rather than an
instance of ElasticSearch.pm

In other words, you're doing something like this:

$es = 'type7_1';
$es->index(.....)

Perhaps you are trying to chain method calls?

$es = ElasticSearch->new()->use_type('type7_1')->index(...) ?

The methods in ElasticSearch.pm are not chainable

clint


(Jérome) #6

Ah forgot the code.
I understand with your help but i don't see my problem.

sub lireFasta {
my @paramIndex = $_[0]; #contain index name and type name

				my $es = $_[1]; # $_[1] contain an instance of ElasticSearch,

i've checked that

				my $in = Bio::SeqIO -> new(-file => $ARGV[0], -format =>

'fasta');
my $result;

				#Recuperation sequences
				my $i = 1;
				while ( my $seq = $in->next_seq() ) {
					my $id       = $seq->primary_id;
					my $desc	 = $seq->desc;
					my $sequence = $seq->seq;


				  	$result = $es->index(
					    index   => $paramIndex[0],     # THIS LINE
					    type    => $paramIndex[1],
					    id      => $i,
					    data    => {
					        ID     => $id,
					        DESC   => $desc,
					        SEQ    => $sequence
					    },
					);


				  	$i++;
				}


			}

On Apr 17, 12:26 pm, Clinton Gormley cl...@traveljury.com wrote:

Can't locate object method "index" via package "type7_1" (perhaps you
forgot to load "type7_1"?) at lectureFichiers.pm line 36, line
1.

You don't show the code, but you are calling method 'index' on a
variable, and that variable contains the value 'type7_1', rather than an
instance of ElasticSearch.pm

In other words, you're doing something like this:

$es = 'type7_1';
$es->index(.....)

Perhaps you are trying to chain method calls?

$es = ElasticSearch->new()->use_type('type7_1')->index(...) ?

The methods in ElasticSearch.pm are not chainable

clint

On Apr 17, 12:26 pm, Clinton Gormley cl...@traveljury.com wrote:

Can't locate object method "index" via package "type7_1" (perhaps you
forgot to load "type7_1"?) at lectureFichiers.pm line 36, line
1.

You don't show the code, but you are calling method 'index' on a
variable, and that variable contains the value 'type7_1', rather than an
instance of ElasticSearch.pm

In other words, you're doing something like this:

$es = 'type7_1';
$es->index(.....)

Perhaps you are trying to chain method calls?

$es = ElasticSearch->new()->use_type('type7_1')->index(...) ?

The methods in ElasticSearch.pm are not chainable

clint


(Clinton Gormley) #7

Hi Jerome

This isn't the right forum for this question, as your issue is purely
with Perl, nothing to do with ElasticSearch.

Also, much better to gist code (http://gist.github.com/gists) rather
than pasting into an email.

sub lireFasta {
my @paramIndex = $_[0]; #contain index name and type name

The above line isn't doing what you think it is doing.

I bet you are calling this sub as: lireFasta(@index_and_type,$es)

but the contents of @index_and_type are flattened, so you end up with:

lireFasta('index','type',$es)

You need to pass the array as a reference instead:

lireFasta(\@index_and_type,$es)
sub lireFasta {
    my $paramIndex = $_[0];
    my $es = $_[1];

    ....
    $es->index(
        index => $paramIndex->[0],
        type  => $paramIndex->[1]

....

clint


(Jérome) #8

Aaaaah, i don't know that... But thank you, it works.

Thank you very much and thanks for the PERL module !

On Apr 17, 12:53 pm, Clinton Gormley cl...@traveljury.com wrote:

Hi Jerome

This isn't the right forum for this question, as your issue is purely
with Perl, nothing to do with ElasticSearch.

Also, much better to gist code (http://gist.github.com/gists) rather
than pasting into an email.

sub lireFasta {
my @paramIndex = $_[0]; #contain index name and type name

The above line isn't doing what you think it is doing.

I bet you are calling this sub as: lireFasta(@index_and_type,$es)

but the contents of @index_and_type are flattened, so you end up with:

lireFasta('index','type',$es)

You need to pass the array as a reference instead:

lireFasta(\@index_and_type,$es)
sub lireFasta {
    my $paramIndex = $_[0];
    my $es = $_[1];

    ....
    $es->index(
        index => $paramIndex->[0],
        type  => $paramIndex->[1]

....

clint


(Jérome) #9

I have two more question, concerning the update method in your perl
API.

This method can change the data in an existing index but if i want add
a field can i use it ?

for example if i have :

...
data{
name => toto,
surname => tata,
age => 18
},
};

Can i add a field for have : ?
...
data{
name => toto,
surname => tata,
age => 18,
newfield => tutu
},
};

One more thing, can you explain one line of your doc ?

$es->update(
index => 'test',
type => 'foo',
id => 123,
script => 'ctx._source.tags+=[tag]', # This one
params => { tag => 'red' }
);

I don't understand, ''ctx._source.tags" is a script name ? and
"+=[tag]" significate you want add a tag ?
Your doc is really good except on this point (in my point of view).

Jerome


(Clinton Gormley) #10

HIya

This method can change the data in an existing index but if i want add
a field can i use it ?

yes

$es->update(
index => 'test',
type => 'foo',
id => 123,
script => 'ctx._source.tags+=[tag]', # This one
params => { tag => 'red' }
);

I don't understand, ''ctx._source.tags" is a script name ? and
"+=[tag]" significate you want add a tag ?
Your doc is really good except on this point (in my point of view).

Yes, that is a script, but I can't explain all about mvel scripting in
my API docs.

The docs in ElasticSearch.pm can't be read in isolation - you also need
to read the docs on elasticsearch.org. The relevant page is linked to
just under the docs that you quote above

https://metacpan.org/module/ElasticSearch#update-

clint


(system) #11