public function SearchApiElasticsearchConnectorStats::logStat in Elasticsearch Connector 7.5
Same name and namespace in other branches
- 7 modules/elasticsearch_connector_search_api/includes/elasticsearch_stats.inc \SearchApiElasticsearchConnectorStats::logStat()
- 7.2 modules/elasticsearch_connector_search_api/includes/elasticsearch_stats.inc \SearchApiElasticsearchConnectorStats::logStat()
Logging the statistics into the stats type in elasticsearch index.
Parameters
array $response: The response array from elasticsearch client.
Return value
array The result of the elasticsearch client execution.
File
- modules/
elasticsearch_connector_search_api/ includes/ elasticsearch_stats.inc, line 187 - @author nikolayignatov
Class
Code
public function logStat($response) {
global $user;
// Skip the log if the results matched.
if (!empty($this->index->options['log_only_not_found']) && !empty($response['hits']['total'])) {
return array();
}
$client = $this->connector
->getConnectorObject();
$doc = $this
->getIndexParam();
try {
// Indexing document.
if (!$client
->indices()
->exists(array(
'index' => $doc['index'],
))) {
$this
->createStatsIndex($doc);
}
$doc['body'] = array(
'server_name' => $this->server->machine_name,
'index_name' => $this->index->machine_name,
'keywords_original' => $this
->getOriginalKeys(),
'keywords' => $this
->parseKeys($this->query
->getOriginalKeys()),
'filters' => $this
->getFilters(),
'sort' => $this
->getSort(),
'uid' => $user->uid,
'results' => isset($response['hits']['total']) ? $response['hits']['total'] : 0,
'username' => $user->uid > 0 ? $user->name : '',
'ip' => ip_address(),
'timestamp' => time(),
);
$ret = $client
->index($doc);
return $ret;
} catch (Exception $e) {
watchdog('elasticsearch_connector_statistics', $e
->getMessage(), array(), WATCHDOG_ERROR);
return array();
}
}