Updated examples

This commit is contained in:
delvedor
2020-09-03 18:30:56 +02:00
parent 917cb534b1
commit ecccaf023e
7 changed files with 375 additions and 60 deletions

View File

@ -18,9 +18,12 @@
*/
import { Client } from '../../'
import { Q, A } from '../'
import { Q, A, F } from '../'
async function run () {
/**
* Pure function API
*/
async function run1 () {
const client = new Client({ node: 'http://localhost:9200' })
// top committers aggregation
@ -44,4 +47,31 @@ async function run () {
console.log(body.aggregations)
}
run().catch(console.log)
/**
* Fluent API
*/
async function run2 () {
const client = new Client({ node: 'http://localhost:9200' })
// top committers aggregation
// 'committers' is the name of the aggregation
const committersAgg = A.committers.terms(
{ field: 'committer.name.keyword' },
// you can nest multiple aggregations by
// passing them to the aggregation constructor
// 'line_stats' is the name of the aggregation
A.line_stats.stats({ field: 'stat.insertions' })
)
const { body } = await client.search({
index: 'git',
body: new F()
.matchAll()
.size(0)
.aggs(committersAgg)
})
console.log(body.aggregations)
}
run1().catch(console.log)
run2().catch(console.log)