Elasticsearch php api is very slow


#1

I'm using elasticsearch-php api version 6.0 and find it very slow to index or get a document.it always take 7-10 secs to perform a request. However when I'm using raw curl request,it only takes 100ms. I wonder why is this happening. I have already found the code that takes a lot of time to execute but I am not sure how to fix it. The code is listed below, it is located at elasticsearch\elasticsearch\src\Elasticsearch\Connections\Connection.php
and the code:"$future = $handler($request, $this, $transport, $options);" is the reason for slow
/**
* @param $method
* @param $uri
* @param null $params
* @param null $body
* @param array $options
* @param \Elasticsearch\Transport $transport
* @return mixed
*/
public function performRequest($method, $uri, $params = null, $body = null, $options = , Transport $transport = null)
{
if (isset($body) === true) {
$body = $this->serializer->serialize($body);
}

    $request = [
        'http_method' => $method,
        'scheme'      => $this->transportSchema,
        'uri'         => $this->getURI($uri, $params),
        'body'        => $body,
        'headers'     => array_merge([
            'Host'  => [$this->host]
        ], $this->headers)
    ];

    $request = array_replace_recursive($request, $this->connectionParams, $options);

    // RingPHP does not like if client is empty
    if (empty($request['client'])) {
        unset($request['client']);
    }

    $handler = $this->handler;
    $future = $handler($request, $this, $transport, $options);

    return $future;
}

#2

Any help or any other good php api for elasticsearch?


(randel) #3

Not sure if that solves your problem, but there is https://elastica.io/


#4

Thx for help,I've tried that however the api documentation is not quite clear


(system) closed #5

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.