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

Retain aggregation data retrieved from Elasticsearch #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ametad
Copy link

@ametad ametad commented Jan 8, 2020

Hello Basem Khirat,

Your package helped me out a great deal, thank you!
I like to use some extra data retrieved from Elasticsearch, some already included (but not all):

\Basemkhirat\Elasticsearch\Query

            $new->total = $result["hits"]["total"];
            $new->max_score = $result["hits"]["max_score"];
            $new->took = $result["took"];
            $new->timed_out = $result["timed_out"];  // typical Elasticsearch data
            $new->scroll_id = isset($result["_scroll_id"]) ? $result["_scroll_id"] : NULL;  // typical Elasticsearch data
            $new->shards = (object)$result["_shards"];  // typical Elasticsearch data

I would like to add this data so I can use this in my application:

            $new->aggregations = isset($result['aggregations']) ? (object) $result['aggregations'] : NULL;

Nothing further has to be changed in you package, but with this change aggregations can be retrieved as follows:

$rules = [
    'query' => [
        // ...
    ],
    'aggs' => [
        // ...
    ],
];

$result = MyModel::body($rules)->paginate();
$result->getCollection()->aggregations;

@ametad
Copy link
Author

ametad commented Jan 28, 2020

@basemkhirat The tests fail also without my additions to the code base. I hope the tests failing is not a problem for you accepting my PR?

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

Successfully merging this pull request may close these issues.

None yet

1 participant