Connection impossible to es

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

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

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

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 ?

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

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

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 (Discover gists · GitHub) 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

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 (Discover gists · GitHub) 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

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

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