I keep getting a no alive nodes found in your cluster message when trying to index or search for documents
$hosts = ['http://localhost:9200/'];
$client = Clientbuilder::create()->setHosts($hosts)->build();
$user = User::find(61);
$params = [
'index' => 'twitter',
'type' => 'users',
'id' => $user->id,
'body' => [
'name' =>$user->username,
'email' =>$user->email
]
];
$response = $client->index($params);
print_r($response);
Sorry for the delay, was getting married and then a work trip :)
I'm assuming the script is running inside the Homestead vagrant box, not from the cli on your native machine? Can you confirm that ES is accessible from localhost:9200 via a curl?
$ curl -XGET localhost:9200
It's not accessible no sever found , I installed it using composer on a laravel project
Sent from my iPhone
On Jul 5, 2016, at 11:58 AM, Zachary Tong [email protected] wrote:
Sorry for the delay, was getting married and then a work trip :)
I'm assuming the script is running inside the Homestead vagrant box, not from the cli on your native machine? Can you confirm that ES is accessible from localhost:9200 via a curl?
$ curl -XGET localhost:9200
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
I have also experienced this problem,most of this problem is caused by curl client node timeout.please check your elasticsearch whether is running or is accessible. if the es is running, run the command:netstat -lntp, you will see the process of binding 9200 port
It's not accessible no sever found , I installed it using composer on a laravel project
Sorry, this isn't really enough detail for me to help. :( Do you mean Elasticsearch isn't running? It's running but you cannot connect via curl? It's running, you can connect via curl, but not by the client? Is the script running inside the vagrant instance, or outside the instance? If it's outside the vagrant instance, you'll have to setup port forwarding to expose the Elasticsearch port to the "outside world".
++ to the command that @dapangxiaozi suggested too
How do I check if running, I can't connect via curl command
Sent from my iPhone
On Jul 6, 2016, at 10:31 AM, Zachary Tong [email protected] wrote:
It's not accessible no sever found , I installed it using composer on a laravel project
Sorry, this isn't really enough detail for me to help. :( Do you mean Elasticsearch isn't running? It's running but you cannot connect via curl? It's running, you can connect via curl, but not by the client? Is the script running inside the vagrant instance, or outside the instance? If it's outside the vagrant instance, you'll have to setup port forwarding to expose the Elasticsearch port to the "outside world".
++ to the command that @dapangxiaozi suggested too
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
To be honest, I'm not super familiar with Homestead. So bear with me :) I'm assuming you installed Homestead with something like this?
$ composer require laravel/homestead --dev
$ php vendor/bin/homestead make
Once Homestead was installed, where did you install Elasticsearch? Did you do something like:
# Login into vagrant box
$ vagrant ssh
# Install elasticsearch inside vagrant
...
...
? If you installed Elasticsearch inside of the vagrant machine, you'll need to forward the ports. I believe this is done in the homestead.yaml config file, based on the documentation:
ports:
- send: 9200
to: 9200
protocol: tcp
Or did you install Elasticsearch directly on your machine (without running the vagrant ssh command)? If you did this, you'll still have to forward ports but we may also need to modify Elasticsearch's config to allow non-localhost connections.
I installed it in my vagrant machine running the vagrant ssh command and
via composer just like the directions on your github
https://github.com/elastic/elasticsearch-php
everything is inside my vendor folder.
I forwarded the ports like you said.
ports:
- send: 9200
to: 9200
protocol: tcp
and still get this error : curl: (7)
Failed to connect to localhost port 9200: Connection refused
I'm running curl -XGET localhost:9200 inside my vagrant box after running (vagrant ssh)
do i need to start the elastic search server bin/elasticsearch after i vagrant ssh or does it automatically start after i vagrant up my homestead server? I tried bin/elasticsearch after vagrant ssh and said command not found?
I was able to get elastic search installed outside my vagrant box and get it to work, but I uninstalled it because I want to get it to work inside homestead with my larval project.
On Thu, Jul 7, 2016 at 10:13 AM, Zachary Tong [email protected]
wrote:
To be honest, I'm not super familiar with Homestead. So bear with me :)
I'm assuming you installed Homestead with something like this?$ composer require laravel/homestead --dev
$ php vendor/bin/homestead makeOnce Homestead was installed, where did you install Elasticsearch? Did you
do something like:Login into vagrant box
$ vagrant ssh
Install elasticsearch inside vagrant
...
...? If you installed Elasticsearch inside of the vagrant machine, you'll
need to forward the ports. I believe this is done in the homestead.yaml
config file, based on the documentation
https://laravel.com/docs/5.1/homestead#installation-and-setup:ports:
- send: 9200
to: 9200
protocol: tcpOr did you install Elasticsearch directly on your machine (without running
the vagrant ssh command)? If you did this, you'll still have to forward
ports but we may also need to modify Elasticsearch's config to allow
non-localhost connections.—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/elastic/elasticsearch-php/issues/425#issuecomment-231089759,
or mute the thread
https://github.com/notifications/unsubscribe/AMOitIpzHFW79jl1nOAmC32rp25eT0_3ks5qTQl3gaJpZM4I_qKp
.
Ah, sorry, that explains my confusion.
The Homestead vagrant instance is a pre-rolled image that includes: Laravel, Nginx, PHP 5.6, MySQL, Postgres, Redis, Memcached. You'll need to download and install Elasticsearch separately, you can download it here: https://www.elastic.co/downloads/elasticsearch
So I'd ssh into the vagrant box, download ES and start it up. If you want to install the deb package and auto-start the service, it would look something like this (based on the docs here):
$ vagrant ssh
$ wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
$ echo "deb https://packages.elastic.co/elasticsearch/2.x/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch-2.x.list
$ sudo apt-get update && sudo apt-get install elasticsearch
$ sudo service elasticsearch start
$ sudo update-rc.d elasticsearch defaults 95 10
You should be able to connect locally then:
curl -XGET localhost:9200/
What you installed from this repo is just the client. It's used to talk to Elasticsearch via PHP... it doesn't provide the actual server, which is why you need to install it separately.
Sorry for my confusion!
Thanks, I installed it again separately on my local machine got it working with curl -XGET localhost:9200/.
But i still keep getting this error: No alive nodes found in your cluster when trying to search in larvavel
I also noticed this error along with a long list of other info that came back in my view:
Failed to connect to localhost port 9200: Connection refused', 'errno' => '7
I indexed the example posted on elastic/elasticsearch github page , was able to post and retrieve it using the curl command.
My problem is i can't seem to get elastic search to cooperate with Laravel.
here's the code i used to try to search the example content:
`
$client = Elasticsearch\Clientbuilder::create()->build();
$results = [
"index" => "twitter",
"type" => "tweet",
"body" => [
"query" => [
"match" => [
"user" => "kimchy"
]
]
]
];
$response = $client->search($results);
print_r($response);
`
OK finally got it to work!
I followed the steps provided to install it inside my virtual machine
$ vagrant ssh $ wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - $ echo "deb https://packages.elastic.co/elasticsearch/2.x/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch-2.x.list $ sudo apt-get update && sudo apt-get install elasticsearch $ sudo service elasticsearch start $ sudo update-rc.d elasticsearch defaults 95 10
the only issue i had was I kept getting set JAVA_HOME path when trying to
sudo service elastic search start
solution for me was to just instal the java sdk
sudo apt-add-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
i tested it by running
curl -XGET localhost:9200/
inside my virtual machine
then inserted some test data
curl -XPUT 'http://localhost:9200/twitter/user/kimchy?pretty' -d '{ "name" : "Shay Banon" }'
curl -XPUT 'http://localhost:9200/twitter/tweet/1?pretty' -d '
{
"user": "kimchy",
"post_date": "2009-11-15T13:12:00",
"message": "Trying out Elasticsearch, so far so good?"
}'
curl -XPUT 'http://localhost:9200/twitter/tweet/2?pretty' -d '
{
"user": "kimchy",
"post_date": "2009-11-15T14:12:12",
"message": "Another tweet, will it be indexed?"
}'
then pulled that data using my larval app
$client = Elasticsearch\Clientbuilder::create()->build();
$results = [
"index" => "twitter",
"type" => "tweet",
"body" => [
"query" => [
"match" => [
"user" => "kimchy"
]
]
]
];
$response = $client->search($results);
print_r($response);
i also forwarded the ports in homestead.yaml file, although I'm not sure if that's necessary , But i did it anyway and it works fine
ports:
- send: 9200
to: 9200
protocol: tcp
everything works fine now!
Most helpful comment
Ah, sorry, that explains my confusion.
The Homestead vagrant instance is a pre-rolled image that includes: Laravel, Nginx, PHP 5.6, MySQL, Postgres, Redis, Memcached. You'll need to download and install Elasticsearch separately, you can download it here: https://www.elastic.co/downloads/elasticsearch
So I'd ssh into the vagrant box, download ES and start it up. If you want to install the deb package and auto-start the service, it would look something like this (based on the docs here):
You should be able to connect locally then:
What you installed from this repo is just the client. It's used to talk to Elasticsearch via PHP... it doesn't provide the actual server, which is why you need to install it separately.
Sorry for my confusion!