msearch example



            $indexer = $this->registry->getIndexer($entityName);
            $alias = $this->adminEsHelper->getIndex($indexer->getName());
            $index[] = ['index' => $alias];
            $query = $indexer->globalCriteria($term$this->buildSearch($term$limit))->toArray();
            $query['timeout'] = $this->timeout;

            $index[] = $query;
        }

        $responses = $this->client->msearch(['body' => $index]);

        $result = [];
        foreach ($responses['responses'] as $response) {
            if (empty($response['hits']['hits'])) {
                continue;
            }

            $index = $response['hits']['hits'][0]['_index'];

            $result[$index] = [
                'total' => $response['hits']['total']['value'],
                
return $response;
    }

    /** * @param array<mixed> $params * * @return array<mixed> */
    public function msearch(array $params = [])
    {
        $time = microtime(true);
        $response = parent::msearch($params);

        $backtrace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 2);

        $connection = $this->transport->getConnection();

        $this->requests[] = [
            'url' => sprintf('%s://%s:%d/_msearch', $connection->getTransportSchema()$connection->getHost()$connection->getPort()),
            'request' => $params,
            'response' => $response,
            'time' => microtime(true) - $time,
            'backtrace' => sprintf('%s:%s', $backtrace[1]['class'] ?? '', $backtrace[1]['function']),
        ];
Home | Imprint | This part of the site doesn't use cookies.