From 3510c3d2819b8f4b91ec007abde813bdc52e21b7 Mon Sep 17 00:00:00 2001 From: Tomas Della Vedova Date: Fri, 26 Jun 2020 12:00:14 +0200 Subject: [PATCH] Fix API example usage (#1234) --- README.md | 12 +++++++-- docs/introduction.asciidoc | 39 ++++++++++++++++++++++------- docs/usage.asciidoc | 50 +++++++++++++++++++++++++++++++------- 3 files changed, 81 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 14875c020..a54a88307 100644 --- a/README.md +++ b/README.md @@ -76,13 +76,21 @@ You can use both the callback-style API and the promise-style API, both behave t // promise API const result = await client.search({ index: 'my-index', - body: { foo: 'bar' } + body: { + query: { + match: { hello: 'world' } + } + } }) // callback API client.search({ index: 'my-index', - body: { foo: 'bar' } + body: { + query: { + match: { hello: 'world' } + } + } }, (err, result) => { if (err) console.log(err) }) diff --git a/docs/introduction.asciidoc b/docs/introduction.asciidoc index 99557aca8..a7e947292 100644 --- a/docs/introduction.asciidoc +++ b/docs/introduction.asciidoc @@ -22,9 +22,12 @@ npm install @elastic/elasticsearch The minimum supported version of Node.js is `v8`. -The library is compatible with all Elasticsearch versions since 5.x, and you should use the same major version of the Elasticsearch instance that you are using. +The library is compatible with all {es} versions since 5.x. We recommend you to +use the same major version of the client as the {es} instance that you are +using. -[%header,cols=2*] + +[%header,cols=2*] |=== |Elasticsearch Version |Client Version @@ -49,8 +52,10 @@ npm install @elastic/elasticsearch@ ==== Browser -WARNING: There is no official support for the browser environment. It exposes your Elasticsearch instance to everyone, which could lead to security issues. -We recommend that you write a lightweight proxy that uses this client instead. +WARNING: There is no official support for the browser environment. It exposes +your {es} instance to everyone, which could lead to security issues. We +recommend you to write a lightweight proxy that uses this client instead. + === Quick start @@ -67,13 +72,21 @@ You can use both the callback-style API and the promise-style API, both behave t // promise API const result = await client.search({ index: 'my-index', - body: { foo: 'bar' } + body: { + query: { + match: { hello: 'world' } + } + } }) // callback API client.search({ index: 'my-index', - body: { foo: 'bar' } + body: { + query: { + match: { hello: 'world' } + } + } }, (err, result) => { if (err) console.log(err) }) @@ -152,7 +165,11 @@ run().catch(console.log) If you are using multiple versions of Elasticsearch, you need to use multiple versions of the client. + In the past, install multiple versions of the same package was not possible, but with `npm v6.9`, you can do that via aliasing. -The command you must run to install different version of the client is: +If you are using multiple versions of {es}, you need to use multiple versions of +the client as well. In the past, installing multiple versions of the same +package was not possible, but with `npm v6.9`, you can do it via aliasing. + +To install different version of the client, run the following command: [source,sh] ---- @@ -189,9 +206,13 @@ client6.info(console.log) client7.info(console.log) ---- -Finally, if you want to install the client for the next version of Elasticsearch (the one that lives in Elasticsearch's master branch), you can use the following command: + +Finally, if you want to install the client for the next version of {es} (the one +that lives in the {es} master branch), use the following command: + [source,sh] ---- npm install esmaster@github:elastic/elasticsearch-js ---- -WARNING: This command will install the master branch of the client, which is not considered stable. +WARNING: This command installs the master branch of the client which is not +considered stable. diff --git a/docs/usage.asciidoc b/docs/usage.asciidoc index bc1eeb60f..a66a469c5 100644 --- a/docs/usage.asciidoc +++ b/docs/usage.asciidoc @@ -11,13 +11,21 @@ const client = new Client({ node: 'http://localhost:9200' }) // promise API const result = await client.search({ index: 'my-index', - body: { foo: 'bar' } + body: { + query: { + match: { hello: 'world' } + } + } }) // callback API client.search({ index: 'my-index', - body: { foo: 'bar' } + body: { + query: { + match: { hello: 'world' } + } + } }, (err, result) => { if (err) console.log(err) }) @@ -47,13 +55,21 @@ The `meta` key contains all the information regarding the request, such as attem // promise API const { body } = await client.search({ index: 'my-index', - body: { foo: 'bar' } + body: { + query: { + match: { hello: 'world' } + } + } }) // callback API client.search({ index: 'my-index', - body: { foo: 'bar' } + body: { + query: { + match: { hello: 'world' } + } + } }, (err, { body }) => { if (err) console.log(err) }) @@ -68,7 +84,11 @@ When using the callback style API, the function will also return an object that // calback API const request = client.search({ index: 'my-index', - body: { foo: 'bar' } + body: { + query: { + match: { hello: 'world' } + } + } }, { ignore: [404], maxRetries: 3 @@ -98,7 +118,11 @@ function abortableRequest (params, options) { const request = abortableRequest({ index: 'my-index', - body: { foo: 'bar' } + body: { + query: { + match: { hello: 'world' } + } + } }, { ignore: [404], maxRetries: 3 @@ -115,16 +139,24 @@ If needed you can pass request specific options in a second object: // promise API const result = await client.search({ index: 'my-index', - body: { foo: 'bar' } + body: { + query: { + match: { hello: 'world' } + } + } }, { ignore: [404], maxRetries: 3 }) -// calback API +// callback API client.search({ index: 'my-index', - body: { foo: 'bar' } + body: { + query: { + match: { hello: 'world' } + } + } }, { ignore: [404], maxRetries: 3