Updated examples
This commit is contained in:
@ -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)
|
||||
|
||||
Reference in New Issue
Block a user