Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collapse #314

Open
patie opened this issue Mar 18, 2020 · 2 comments
Open

Collapse #314

patie opened this issue Mar 18, 2020 · 2 comments

Comments

@patie
Copy link

patie commented Mar 18, 2020

Can you please add collapse?

https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-collapse.html

@SomethingWrong
Copy link

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);

@maluramichael
Copy link

maluramichael commented Mar 4, 2021

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));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants