Cake\ElasticSearch\Query::compileQuery PHP Method

compileQuery() public method

Compile the Elasticsearch query.
public compileQuery ( ) : string
return string The Elasticsearch query.
    public function compileQuery()
    {
        if ($this->_parts['fields']) {
            $this->_elasticQuery->setSource($this->_parts['fields']);
        }
        if (isset($this->_parts['limit'])) {
            $this->_elasticQuery->setSize($this->_parts['limit']);
        }
        if (isset($this->_parts['offset'])) {
            $this->_elasticQuery->setFrom($this->_parts['offset']);
        }
        if ($this->_parts['order']) {
            $this->_elasticQuery->setSort($this->_parts['order']);
        }
        if ($this->_parts['highlight']) {
            $this->_elasticQuery->setHighlight($this->_parts['highlight']);
        }
        if ($this->_parts['aggregations']) {
            foreach ($this->_parts['aggregations'] as $aggregation) {
                $this->_elasticQuery->addAggregation($aggregation);
            }
        }
        $filteredQuery = new FilteredQuery();
        if ($this->_parts['query'] !== null) {
            $filteredQuery->setQuery($this->_parts['query']);
            $this->_elasticQuery->setQuery($filteredQuery);
        }
        if ($this->_parts['preFilter'] !== null) {
            $filteredQuery->setFilter($this->_parts['preFilter']);
            $this->_elasticQuery->setQuery($filteredQuery);
        }
        if ($this->_parts['postFilter'] !== null) {
            $this->_elasticQuery->setPostFilter($this->_parts['postFilter']);
        }
        return $this->_elasticQuery;
    }