Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 05921b134d | |||
| aadf44bbf2 | |||
| bef1604a8d | |||
| 87fb0a2996 | |||
| 456fc19c94 | |||
| 4c118b9f9a | |||
| dc5c041b07 | |||
| 6774560444 |
@ -1,5 +1,6 @@
|
|||||||
---
|
---
|
||||||
ELASTICSEARCH_VERSION:
|
ELASTICSEARCH_VERSION:
|
||||||
|
- 6.8.0
|
||||||
- 6.7.1
|
- 6.7.1
|
||||||
|
|
||||||
NODE_JS_VERSION:
|
NODE_JS_VERSION:
|
||||||
|
|||||||
@ -150,6 +150,26 @@ function generateRequestId (params, options) {
|
|||||||
|`name`
|
|`name`
|
||||||
|`string` - The name to identify the client instance in the events. +
|
|`string` - The name to identify the client instance in the events. +
|
||||||
_Default:_ `elasticsearch-js`
|
_Default:_ `elasticsearch-js`
|
||||||
|
|
||||||
|
|`headers`
|
||||||
|
|`object` - A set of custom headers to send in every request. +
|
||||||
|
_Default:_ `{}`
|
||||||
|
|
||||||
|
|`cloud`
|
||||||
|
a|`object` - Custom configuration for connecting to https://cloud.elastic.co[Elastic Cloud]. See https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/auth-reference.html[Authentication] for more details. +
|
||||||
|
_Default:_ `null` +
|
||||||
|
_Cloud configuration example:_
|
||||||
|
[source,js]
|
||||||
|
----
|
||||||
|
const client = new Client({
|
||||||
|
cloud: {
|
||||||
|
id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==',
|
||||||
|
username: 'elastic',
|
||||||
|
password: 'changeme'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
----
|
||||||
|
|
||||||
|===
|
|===
|
||||||
|
|
||||||
=== Advanced configuration
|
=== Advanced configuration
|
||||||
|
|||||||
@ -59,7 +59,7 @@ async function run (): void {
|
|||||||
client
|
client
|
||||||
.search(params)
|
.search(params)
|
||||||
.then((result: ApiResponse) => {
|
.then((result: ApiResponse) => {
|
||||||
console.og(result.body.hits.hits)
|
console.log(result.body.hits.hits)
|
||||||
})
|
})
|
||||||
.catch((err: Error) => {
|
.catch((err: Error) => {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
|
|||||||
22
index.d.ts
vendored
22
index.d.ts
vendored
@ -20,7 +20,7 @@
|
|||||||
/// <reference types="node" />
|
/// <reference types="node" />
|
||||||
|
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
import { SecureContextOptions } from 'tls';
|
import { ConnectionOptions as TlsConnectionOptions } from 'tls';
|
||||||
import Transport, {
|
import Transport, {
|
||||||
ApiResponse,
|
ApiResponse,
|
||||||
RequestEvent,
|
RequestEvent,
|
||||||
@ -31,6 +31,7 @@ import Transport, {
|
|||||||
generateRequestIdFn,
|
generateRequestIdFn,
|
||||||
TransportRequestCallback
|
TransportRequestCallback
|
||||||
} from './lib/Transport';
|
} from './lib/Transport';
|
||||||
|
import { URL } from 'url';
|
||||||
import Connection, { AgentOptions, agentFn } from './lib/Connection';
|
import Connection, { AgentOptions, agentFn } from './lib/Connection';
|
||||||
import ConnectionPool, { ResurrectEvent } from './lib/ConnectionPool';
|
import ConnectionPool, { ResurrectEvent } from './lib/ConnectionPool';
|
||||||
import Serializer from './lib/Serializer';
|
import Serializer from './lib/Serializer';
|
||||||
@ -72,8 +73,22 @@ interface ClientExtends {
|
|||||||
}
|
}
|
||||||
// /Extend API
|
// /Extend API
|
||||||
|
|
||||||
|
interface NodeOptions {
|
||||||
|
url: URL;
|
||||||
|
id?: string;
|
||||||
|
agent?: AgentOptions;
|
||||||
|
ssl?: TlsConnectionOptions;
|
||||||
|
headers?: anyObject;
|
||||||
|
roles?: {
|
||||||
|
master: boolean;
|
||||||
|
data: boolean;
|
||||||
|
ingest: boolean;
|
||||||
|
ml: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface ClientOptions {
|
interface ClientOptions {
|
||||||
node?: string | string[];
|
node?: string | string[] | NodeOptions | NodeOptions[];
|
||||||
nodes?: string | string[];
|
nodes?: string | string[];
|
||||||
Connection?: typeof Connection;
|
Connection?: typeof Connection;
|
||||||
ConnectionPool?: typeof ConnectionPool;
|
ConnectionPool?: typeof ConnectionPool;
|
||||||
@ -89,7 +104,7 @@ interface ClientOptions {
|
|||||||
resurrectStrategy?: 'ping' | 'optimistic' | 'none';
|
resurrectStrategy?: 'ping' | 'optimistic' | 'none';
|
||||||
suggestCompression?: boolean;
|
suggestCompression?: boolean;
|
||||||
compression?: 'gzip';
|
compression?: 'gzip';
|
||||||
ssl?: SecureContextOptions;
|
ssl?: TlsConnectionOptions;
|
||||||
agent?: AgentOptions | agentFn;
|
agent?: AgentOptions | agentFn;
|
||||||
nodeFilter?: nodeFilterFn;
|
nodeFilter?: nodeFilterFn;
|
||||||
nodeSelector?: nodeSelectorFn | string;
|
nodeSelector?: nodeSelectorFn | string;
|
||||||
@ -588,5 +603,6 @@ export {
|
|||||||
ResurrectEvent,
|
ResurrectEvent,
|
||||||
RequestParams,
|
RequestParams,
|
||||||
ClientOptions,
|
ClientOptions,
|
||||||
|
NodeOptions,
|
||||||
ClientExtendsCallbackOptions
|
ClientExtendsCallbackOptions
|
||||||
};
|
};
|
||||||
|
|||||||
6
lib/Connection.d.ts
vendored
6
lib/Connection.d.ts
vendored
@ -22,13 +22,13 @@
|
|||||||
import { URL } from 'url';
|
import { URL } from 'url';
|
||||||
import { inspect, InspectOptions } from 'util';
|
import { inspect, InspectOptions } from 'util';
|
||||||
import * as http from 'http';
|
import * as http from 'http';
|
||||||
import { SecureContextOptions } from 'tls';
|
import { ConnectionOptions as TlsConnectionOptions } from 'tls';
|
||||||
|
|
||||||
export declare type agentFn = () => any;
|
export declare type agentFn = () => any;
|
||||||
|
|
||||||
interface ConnectionOptions {
|
interface ConnectionOptions {
|
||||||
url: URL;
|
url: URL;
|
||||||
ssl?: SecureContextOptions;
|
ssl?: TlsConnectionOptions;
|
||||||
id?: string;
|
id?: string;
|
||||||
headers?: any;
|
headers?: any;
|
||||||
agent?: AgentOptions | agentFn;
|
agent?: AgentOptions | agentFn;
|
||||||
@ -59,7 +59,7 @@ export default class Connection {
|
|||||||
ML: string;
|
ML: string;
|
||||||
};
|
};
|
||||||
url: URL;
|
url: URL;
|
||||||
ssl: SecureContextOptions | null;
|
ssl: TlsConnectionOptions | null;
|
||||||
id: string;
|
id: string;
|
||||||
headers: any;
|
headers: any;
|
||||||
deadCount: number;
|
deadCount: number;
|
||||||
|
|||||||
@ -231,7 +231,7 @@ class Connection {
|
|||||||
// access them with `instance.agent` and `instance.ssl`.
|
// access them with `instance.agent` and `instance.ssl`.
|
||||||
[inspect.custom] (depth, options) {
|
[inspect.custom] (depth, options) {
|
||||||
return {
|
return {
|
||||||
url: this.url,
|
url: stripAuth(this.url.toString()),
|
||||||
id: this.id,
|
id: this.id,
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
deadCount: this.deadCount,
|
deadCount: this.deadCount,
|
||||||
@ -244,7 +244,7 @@ class Connection {
|
|||||||
|
|
||||||
toJSON () {
|
toJSON () {
|
||||||
return {
|
return {
|
||||||
url: this.url,
|
url: stripAuth(this.url.toString()),
|
||||||
id: this.id,
|
id: this.id,
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
deadCount: this.deadCount,
|
deadCount: this.deadCount,
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"types": "index.d.ts",
|
"types": "index.d.ts",
|
||||||
"homepage": "http://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html",
|
"homepage": "http://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html",
|
||||||
"version": "6.8.0",
|
"version": "6.8.1",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"elasticsearch",
|
"elasticsearch",
|
||||||
"elastic",
|
"elastic",
|
||||||
|
|||||||
@ -35,12 +35,12 @@ const {
|
|||||||
} = require('./utils')
|
} = require('./utils')
|
||||||
|
|
||||||
start(minimist(process.argv.slice(2), {
|
start(minimist(process.argv.slice(2), {
|
||||||
string: ['tag']
|
string: ['tag', 'branch']
|
||||||
}))
|
}))
|
||||||
|
|
||||||
function start (opts) {
|
function start (opts) {
|
||||||
const log = ora('Loading Elasticsearch Repository').start()
|
const log = ora('Loading Elasticsearch Repository').start()
|
||||||
if (semver.valid(opts.tag) === null) {
|
if (opts.branch == null && semver.valid(opts.tag) === null) {
|
||||||
log.fail(`Missing or invalid tag: ${opts.tag}`)
|
log.fail(`Missing or invalid tag: ${opts.tag}`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ function start (opts) {
|
|||||||
log.text = 'Cleaning API folder...'
|
log.text = 'Cleaning API folder...'
|
||||||
rimraf.sync(join(apiOutputFolder, '*.js'))
|
rimraf.sync(join(apiOutputFolder, '*.js'))
|
||||||
|
|
||||||
cloneAndCheckout({ log, tag: opts.tag }, (err, { apiFolder, xPackFolder }) => {
|
cloneAndCheckout({ log, tag: opts.tag, branch: opts.branch }, (err, { apiFolder, xPackFolder }) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
log.fail(err.message)
|
log.fail(err.message)
|
||||||
return
|
return
|
||||||
|
|||||||
@ -29,7 +29,7 @@ const apiFolder = join(esFolder, 'rest-api-spec', 'src', 'main', 'resources', 'r
|
|||||||
const xPackFolder = join(esFolder, 'x-pack', 'plugin', 'src', 'test', 'resources', 'rest-api-spec', 'api')
|
const xPackFolder = join(esFolder, 'x-pack', 'plugin', 'src', 'test', 'resources', 'rest-api-spec', 'api')
|
||||||
|
|
||||||
function cloneAndCheckout (opts, callback) {
|
function cloneAndCheckout (opts, callback) {
|
||||||
const { log, tag } = opts
|
const { log, tag, branch } = opts
|
||||||
withTag(tag, callback)
|
withTag(tag, callback)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,13 +57,19 @@ function cloneAndCheckout (opts, callback) {
|
|||||||
|
|
||||||
if (fresh) {
|
if (fresh) {
|
||||||
clone(checkout)
|
clone(checkout)
|
||||||
|
} else if (opts.branch) {
|
||||||
|
checkout(true)
|
||||||
} else {
|
} else {
|
||||||
checkout()
|
checkout()
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkout () {
|
function checkout (alsoPull = false) {
|
||||||
log.text = `Checking out tag '${tag}'`
|
if (branch) {
|
||||||
git.checkout(tag, err => {
|
log.text = `Checking out branch '${branch}'`
|
||||||
|
} else {
|
||||||
|
log.text = `Checking out tag '${tag}'`
|
||||||
|
}
|
||||||
|
git.checkout(branch || tag, err => {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (retry++ > 0) {
|
if (retry++ > 0) {
|
||||||
callback(new Error(`Cannot checkout tag '${tag}'`), { apiFolder, xPackFolder })
|
callback(new Error(`Cannot checkout tag '${tag}'`), { apiFolder, xPackFolder })
|
||||||
@ -71,6 +77,9 @@ function cloneAndCheckout (opts, callback) {
|
|||||||
}
|
}
|
||||||
return pull(checkout)
|
return pull(checkout)
|
||||||
}
|
}
|
||||||
|
if (alsoPull) {
|
||||||
|
return pull(checkout)
|
||||||
|
}
|
||||||
callback(null, { apiFolder, xPackFolder })
|
callback(null, { apiFolder, xPackFolder })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,13 +27,29 @@ import {
|
|||||||
ResurrectEvent,
|
ResurrectEvent,
|
||||||
events,
|
events,
|
||||||
errors,
|
errors,
|
||||||
ClientExtendsCallbackOptions
|
ClientExtendsCallbackOptions,
|
||||||
|
NodeOptions
|
||||||
} from '../../index'
|
} from '../../index'
|
||||||
|
|
||||||
import { TransportRequestParams, TransportRequestOptions } from '../../lib/Transport'
|
import { TransportRequestParams, TransportRequestOptions } from '../../lib/Transport'
|
||||||
|
import { URL } from 'url'
|
||||||
|
|
||||||
const client = new Client({ node: 'http://localhost:9200' })
|
const client = new Client({ node: 'http://localhost:9200' })
|
||||||
|
|
||||||
|
const nodeOpts: NodeOptions = {
|
||||||
|
url: new URL('http://localhost:9200'),
|
||||||
|
id: 'winteriscoming',
|
||||||
|
headers: { 'foo': 'bar' },
|
||||||
|
roles: {
|
||||||
|
master: false,
|
||||||
|
data: true,
|
||||||
|
ingest: false,
|
||||||
|
ml: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const client2 = new Client({ node: nodeOpts })
|
||||||
|
|
||||||
client.on(events.RESPONSE, (err: errors.ElasticsearchClientError | 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
|
||||||
|
|||||||
@ -723,11 +723,11 @@ test('setRole', t => {
|
|||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Util.inspect Connection class should hide agent and ssl', t => {
|
test('Util.inspect Connection class should hide agent, ssl and auth', t => {
|
||||||
t.plan(1)
|
t.plan(1)
|
||||||
|
|
||||||
const connection = new Connection({
|
const connection = new Connection({
|
||||||
url: new URL('http://localhost:9200'),
|
url: new URL('http://user:password@localhost:9200'),
|
||||||
id: 'node-id',
|
id: 'node-id',
|
||||||
headers: { foo: 'bar' }
|
headers: { foo: 'bar' }
|
||||||
})
|
})
|
||||||
@ -741,20 +741,7 @@ test('Util.inspect Connection class should hide agent and ssl', t => {
|
|||||||
.replace(/(\r\n|\n|\r)/gm, '')
|
.replace(/(\r\n|\n|\r)/gm, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
t.strictEqual(cleanStr(inspect(connection)), cleanStr(`{ url:
|
t.strictEqual(cleanStr(inspect(connection)), cleanStr(`{ url: 'http://localhost:9200/',
|
||||||
URL {
|
|
||||||
href: 'http://localhost:9200/',
|
|
||||||
origin: 'http://localhost:9200',
|
|
||||||
protocol: 'http:',
|
|
||||||
username: '',
|
|
||||||
password: '',
|
|
||||||
host: 'localhost:9200',
|
|
||||||
hostname: 'localhost',
|
|
||||||
port: '9200',
|
|
||||||
pathname: '/',
|
|
||||||
search: '',
|
|
||||||
searchParams: URLSearchParams {},
|
|
||||||
hash: '' },
|
|
||||||
id: 'node-id',
|
id: 'node-id',
|
||||||
headers: { foo: 'bar' },
|
headers: { foo: 'bar' },
|
||||||
deadCount: 0,
|
deadCount: 0,
|
||||||
@ -765,6 +752,34 @@ test('Util.inspect Connection class should hide agent and ssl', t => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('connection.toJSON should hide agent, ssl and auth', t => {
|
||||||
|
t.plan(1)
|
||||||
|
|
||||||
|
const connection = new Connection({
|
||||||
|
url: new URL('http://user:password@localhost:9200'),
|
||||||
|
id: 'node-id',
|
||||||
|
headers: { foo: 'bar' }
|
||||||
|
})
|
||||||
|
|
||||||
|
t.deepEqual(connection.toJSON(), {
|
||||||
|
url: 'http://localhost:9200/',
|
||||||
|
id: 'node-id',
|
||||||
|
headers: {
|
||||||
|
foo: 'bar'
|
||||||
|
},
|
||||||
|
deadCount: 0,
|
||||||
|
resurrectTimeout: 0,
|
||||||
|
_openRequests: 0,
|
||||||
|
status: 'alive',
|
||||||
|
roles: {
|
||||||
|
master: true,
|
||||||
|
data: true,
|
||||||
|
ingest: true,
|
||||||
|
ml: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// https://github.com/elastic/elasticsearch-js/issues/843
|
// https://github.com/elastic/elasticsearch-js/issues/843
|
||||||
test('Port handling', t => {
|
test('Port handling', t => {
|
||||||
t.test('http 80', t => {
|
t.test('http 80', t => {
|
||||||
|
|||||||
Reference in New Issue
Block a user