skr07
skr07

Reputation: 725

Elastic search configuration issue with client call php

I am using elasticsearch API php to build search results. I have configured everything in my xampp server. All the libraries downloaded from composer.json. In my composer.json file contains below code

  {
    "require": {
        "elasticsearch/elasticsearch": "~2.0"
    }
}

Libraries are successfully downloaded. After that i initialize the elastic search with below code

 <?php
    require 'vendor/autoload.php'; 
    $client = ClientBuilder::create()->build();

It shows fatal error like as follows

Fatal error: Class 'ClientBuilder' not found in E:\Xampp\htdocs\codeporn\elasticsearch\app\init.php on line 4

So i change the config code as,

 require_once 'vendor/autoload.php';    
     $es = new Elasticsearch\Client([
        'hosts' => ['127.0.0.1:9200']]
    ]);

This also shows error like

Parse error: syntax error, unexpected ']' in E:\Xampp\htdocs\codeporn\elasticsearch\app\init.php on line 10

I am following the below youtube tutorial to build the search https://www.youtube.com/watch?v=3xb1dHLg-Lk

Please suggest what i went wrong in Elasticsearch - PHP. My PHP Version is 5.5.9

Upvotes: 3

Views: 4100

Answers (2)

Vahid Alvandi
Vahid Alvandi

Reputation: 612

you need install it with composer

composer require elasticsearch/elasticsearch 

Upvotes: 1

skr07
skr07

Reputation: 725

i have initialize the clientbuilder class, now it works fine

require 'vendor/autoload.php';

use Elasticsearch\ClientBuilder;

$client = ClientBuilder::create()->build();

Upvotes: 8

Related Questions