Open patie opened 4 years ago
Just put it to the body
before sending a request.
Here's a rewritten example from readme.md
:
<?php
require 'vendor/autoload.php'; //Composer autoload
$client = ClientBuilder::create()->build(); //elasticsearch-php client
$matchAll = new ONGR\ElasticsearchDSL\Query\MatchAllQuery();
$search = new ONGR\ElasticsearchDSL\Search();
$search->addQuery($matchAll);
$params = [
'index' => 'your_index',
'body' => array_merge(
$search->toArray(),
['collapse' => ['field' => 'field_to_collapse_on']], // Here your collapse param goes
),
];
$results = $client->search($params);
Just FYI how i did it
if ($collapseResults) {
$client = $index->getClient();
$params = [
'index' => $index->getIndexName(),
'body' => array_merge(
$search->toArray(),
['collapse' => ['field' => 'my_field']]
),
];
$results = $client->search($params);
$iterator = new RawIterator(
$results,
$index,
$index->getConverter(),
$index->getScrollConfiguration($results, $search->getScroll())
);
$elasticSearchResults = iterator_to_array($iterator);
} else {
$elasticSearchResults = iterator_to_array($index->findRaw($search));
}
Can you please add collapse?
https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-collapse.html