Skip to content

Commit

Permalink
feat: update search.ts to support @elastic/elasticsearch for aggregat…
Browse files Browse the repository at this point in the history
…ions, took, timed_out (#141)

* Update search.ts to support @elastic/elasticsearch

@elastic/elasticsearch client returns the aggregations inside res.body,

* Update Search.ts - fix for took, timed_out
  • Loading branch information
ajmalmsali authored Jul 12, 2022
1 parent 4110a8b commit 237e909
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/resolvers/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ export default function createSearchResolver<TSource, TContext>(
}

const res: any = await searchFC.resolve(rp.source, args, rp.context, rp.info);
if (typeof res.aggregations === 'undefined') {
res.aggregations = res.body.aggregations;
}
if (typeof res.took === 'undefined') {
res.took = res.body.took;
}
if (typeof res.timed_out === 'undefined') {
res.timed_out = res.body.timed_out;
}
if (typeof res.hits === 'undefined') {
res.count =
typeof res.body.hits.total?.value === 'number'
Expand Down

0 comments on commit 237e909

Please sign in to comment.