# Connection impossible to es

**URL:** <https://discuss.elastic.co/t/connection-impossible-to-es/7365>\
**Category:** Elasticsearch\
**Created:** [April 17, 2012, 9:23am UTC](https://discuss.elastic.co/t/connection-impossible-to-es/7365 "2012-04-17T09:23:29Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jerome](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@Jerome](https://discuss.elastic.co/u/Jerome)\
**Post date:** [April 17, 2012, 9:23am UTC](https://discuss.elastic.co/t/connection-impossible-to-es/7365/1 "2012-04-17T09:23:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [April 17, 2012, 9:31am UTC](https://discuss.elastic.co/t/connection-impossible-to-es/7365/2 "2012-04-17T09:31:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sushis](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@Sushis](https://discuss.elastic.co/u/Sushis)\
**Post date:** [April 17, 2012, 9:45am UTC](https://discuss.elastic.co/t/connection-impossible-to-es/7365/3 "2012-04-17T09:45:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jerome](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@Jerome](https://discuss.elastic.co/u/Jerome)\
**Post date:** [April 17, 2012, 10:18am UTC](https://discuss.elastic.co/t/connection-impossible-to-es/7365/4 "2012-04-17T10:18:39Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [April 17, 2012, 10:26am UTC](https://discuss.elastic.co/t/connection-impossible-to-es/7365/5 "2012-04-17T10:26:47Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![Jerome](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@Jerome](https://discuss.elastic.co/u/Jerome)\
**Post date:** [April 17, 2012, 10:41am UTC](https://discuss.elastic.co/t/connection-impossible-to-es/7365/6 "2012-04-17T10:41:48Z")

</div>

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](mailto: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](mailto: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

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [April 17, 2012, 10:53am UTC](https://discuss.elastic.co/t/connection-impossible-to-es/7365/7 "2012-04-17T10:53:25Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Jerome](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@Jerome](https://discuss.elastic.co/u/Jerome)\
**Post date:** [April 17, 2012, 11:08am UTC](https://discuss.elastic.co/t/connection-impossible-to-es/7365/8 "2012-04-17T11:08:02Z")

</div>

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](mailto: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](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

---

<div class="post-metadata">

**Author:** ![Jerome](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@Jerome](https://discuss.elastic.co/u/Jerome)\
**Post date:** [April 17, 2012, 11:45am UTC](https://discuss.elastic.co/t/connection-impossible-to-es/7365/9 "2012-04-17T11:45:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [April 17, 2012, 11:53am UTC](https://discuss.elastic.co/t/connection-impossible-to-es/7365/10 "2012-04-17T11:53:21Z")

</div>

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](http://elasticsearch.org). The relevant page is linked to  
just under the docs that you quote above

[https://metacpan.org/module/ElasticSearch#update-](https://metacpan.org/module/ElasticSearch#update-)

clint

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:32am UTC](https://discuss.elastic.co/t/connection-impossible-to-es/7365/11 "2017-07-06T03:32:19Z")

</div>


