Updated examples

This commit is contained in:
delvedor
2020-09-14 17:13:49 +02:00
parent e932366caf
commit 7d605485b2

View File

@ -18,15 +18,18 @@
*/
import { Client } from '../../'
import { Q } from '../'
import { Q, F } from '../'
async function run () {
/**
* Pure function API
*/
async function run1 () {
const client = new Client({ node: 'http://localhost:9200' })
// define the query clauses
const fixDescription = Q.must(Q.match('description', 'fix'))
const files = Q.should(Q.term('files', 'test'), Q.term('files', 'docs'))
const author = Q.filter(Q.term('author.name', Q.param('author')))
const author = Q.filter(Q.term('author.name', 'delvedor'))
const { body } = await client.search({
index: 'git',
// use the boolean utilities to craft the final query
@ -36,4 +39,24 @@ async function run () {
console.log(body.hits.hits)
}
run().catch(console.log)
/**
* Fluent API
*/
async function run2 () {
const client = new Client({ node: 'http://localhost:9200' })
// define the query clauses
const fixDescription = F().must(F().match('description', 'fix'))
const files = F().should(F().term('files', 'test').term('files', 'docs'))
const author = F().filter(F().term('author.name', 'delvedor'))
const { body } = await client.search({
index: 'git',
// use the boolean utilities to craft the final query
body: F().and(fixDescription, files, author)
})
console.log(body.hits.hits)
}
run1().catch(console.log)
run2().catch(console.log)