committed by
delvedor
parent
2fa192b94a
commit
1a5d481482
1
index.d.ts
vendored
1
index.d.ts
vendored
@ -321,6 +321,7 @@ export {
|
|||||||
Connection,
|
Connection,
|
||||||
Serializer,
|
Serializer,
|
||||||
events,
|
events,
|
||||||
|
errors,
|
||||||
ApiResponse,
|
ApiResponse,
|
||||||
RequestEvent,
|
RequestEvent,
|
||||||
ResurrectEvent,
|
ResurrectEvent,
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import {
|
|||||||
RequestEvent,
|
RequestEvent,
|
||||||
ResurrectEvent,
|
ResurrectEvent,
|
||||||
events,
|
events,
|
||||||
|
errors,
|
||||||
ClientExtendsCallbackOptions
|
ClientExtendsCallbackOptions
|
||||||
} from '../../index'
|
} from '../../index'
|
||||||
|
|
||||||
@ -33,23 +34,23 @@ import { TransportRequestParams, TransportRequestOptions } from '../../lib/Trans
|
|||||||
|
|
||||||
const client = new Client({ node: 'http://localhost:9200' })
|
const client = new Client({ node: 'http://localhost:9200' })
|
||||||
|
|
||||||
client.on(events.RESPONSE, (err: Error | null, request: RequestEvent) => {
|
client.on(events.RESPONSE, (err: errors.ElasticsearchClientError | null, request: RequestEvent) => {
|
||||||
if (err) console.log(err)
|
if (err) console.log(err)
|
||||||
const { body, statusCode } = request
|
const { body, statusCode } = request
|
||||||
const { params } = request.meta.request
|
const { params } = request.meta.request
|
||||||
console.log(params, body, statusCode)
|
console.log(params, body, statusCode)
|
||||||
})
|
})
|
||||||
client.on(events.RESURRECT, (err: Error | null, meta: ResurrectEvent) => {})
|
client.on(events.RESURRECT, (err: errors.ElasticsearchClientError | null, meta: ResurrectEvent) => {})
|
||||||
|
|
||||||
// Callbacks
|
// Callbacks
|
||||||
client.info((err: Error | null, result: ApiResponse) => {})
|
client.info((err: errors.ElasticsearchClientError | null, result: ApiResponse) => {})
|
||||||
|
|
||||||
client.index({
|
client.index({
|
||||||
index: 'test',
|
index: 'test',
|
||||||
type: 'test',
|
type: 'test',
|
||||||
id: 'test',
|
id: 'test',
|
||||||
body: { hello: 'world' }
|
body: { hello: 'world' }
|
||||||
}, (err: Error | null, result: ApiResponse) => {})
|
}, (err: errors.ElasticsearchClientError | null, result: ApiResponse) => {})
|
||||||
|
|
||||||
// request options
|
// request options
|
||||||
client.index({
|
client.index({
|
||||||
@ -65,12 +66,12 @@ client.index({
|
|||||||
querystring: { baz: 'faz' },
|
querystring: { baz: 'faz' },
|
||||||
compression: 'gzip',
|
compression: 'gzip',
|
||||||
asStream: false
|
asStream: false
|
||||||
}, (err: Error | null, result: ApiResponse) => {})
|
}, (err: errors.ElasticsearchClientError | null, result: ApiResponse) => {})
|
||||||
|
|
||||||
// Promises
|
// Promises
|
||||||
client.info()
|
client.info()
|
||||||
.then((result: ApiResponse) => {})
|
.then((result: ApiResponse) => {})
|
||||||
.catch((err: Error) => {})
|
.catch((err: errors.ElasticsearchClientError) => {})
|
||||||
|
|
||||||
client.index({
|
client.index({
|
||||||
index: 'test',
|
index: 'test',
|
||||||
@ -79,7 +80,7 @@ client.index({
|
|||||||
body: { hello: 'world' }
|
body: { hello: 'world' }
|
||||||
})
|
})
|
||||||
.then((result: ApiResponse) => {})
|
.then((result: ApiResponse) => {})
|
||||||
.catch((err: Error) => {})
|
.catch((err: errors.ElasticsearchClientError) => {})
|
||||||
|
|
||||||
// request options
|
// request options
|
||||||
client.index({
|
client.index({
|
||||||
@ -93,7 +94,7 @@ client.index({
|
|||||||
requestTimeout: 2000
|
requestTimeout: 2000
|
||||||
})
|
})
|
||||||
.then((result: ApiResponse) => {})
|
.then((result: ApiResponse) => {})
|
||||||
.catch((err: Error) => {})
|
.catch((err: errors.ElasticsearchClientError) => {})
|
||||||
|
|
||||||
// --- Use generics ---
|
// --- Use generics ---
|
||||||
// Define the search parameters
|
// Define the search parameters
|
||||||
@ -127,7 +128,7 @@ interface Source {
|
|||||||
|
|
||||||
client.search(searchParams)
|
client.search(searchParams)
|
||||||
.then((response: ApiResponse<SearchResponse<Source>>) => console.log(response))
|
.then((response: ApiResponse<SearchResponse<Source>>) => console.log(response))
|
||||||
.catch((err: Error) => {})
|
.catch((err: errors.ElasticsearchClientError) => {})
|
||||||
|
|
||||||
// extend client
|
// extend client
|
||||||
client.extend('namespace.method', (options: ClientExtendsCallbackOptions) => {
|
client.extend('namespace.method', (options: ClientExtendsCallbackOptions) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user