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' })
// get the day where the most commits were made
@ -41,4 +44,30 @@ async function run () {
console.log(body.aggregations)
}
run().catch(console.log)
/**
* Fluent API
*/
async function run2 () {
const client = new Client({ node: 'http://localhost:9200' })
// get the day where the most commits were made
const { body } = await client.search({
index: 'git',
body: new F()
.size(0)
// 'day_most_commits' is the name of the aggregation
.aggs(
A.day_most_commits.dateHistogram({
field: 'committed_date',
interval: 'day',
min_doc_count: 1,
order: { _count: 'desc' }
})
)
})
console.log(body.aggregations)
}
run1().catch(console.log)
run2().catch(console.log)