elastic / elasticsearch-php

Official PHP client for Elasticsearch.
https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html
MIT License
5.26k stars 966 forks source link

How do I log the Elastic Search Request or Trace Data? #1260

Closed Kailashlambe closed 1 year ago

Kailashlambe commented 1 year ago

Hello There,

I was trying to log the request and trace data, the responsible function which logs the data is,

\Elasticsearch\Connections\Connection::wrapHandler which calls the main log method,

\Elasticsearch\Connections\Connection::logRequestSuccess

but the variable $this->log is the type \Psr\Log\NullLogger which is defined at

\Elasticsearch\ClientBuilder::buildLoggers

`if (is_null($this->logger)) { $this->logger = new NullLogger(); }

    if (is_null($this->tracer)) {
        $this->tracer = new NullLogger();
    }

`

and the log method of NullLogger class has an empty method declaration like

public function log($level, $message, array $context = array()) { //noop }

and that is the reason I am not able to log the request/trace data.

Could you please guide me on how to log the elastic search request?

ezimuel commented 1 year ago

@Kailashlambe if you want to log the request and response of elasticsearch-php you need to enable the logger in the client. Reading your comment, I'm assuming you are using elsticsearch-php ver. 7, here you can find the official documentation for the logger. Let me know if you need more help, thanks.

Kailashlambe commented 1 year ago

Thanks, @ezimuel for the feedback, I am not sure I should use the same thread for another question but I do have small doubt that I wanted to confirm with you, is it not possible to 'sort' the subfield numeric values of field data type 'flattened'?

ezimuel commented 1 year ago

@Kailashlambe reading from the Elasticsearch documentation it seems that is possible to sort a flattened type:

It is possible to sort on a flattened object field, as well as perform simple keyword-style aggregations such as terms

I suggest to ask in https://discuss.elastic.co/. Thanks.