From 4b2cbdb8094c522ffc6d0c85d75fb3e081efba29 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 | 30 ++++++++++++++--------- docs/usage.asciidoc | 50 +++++++++++++++++++++++++++++++------- 3 files changed, 70 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index c4c54b789..c245c4b35 100644 --- a/README.md +++ b/README.md @@ -78,13 +78,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 432b8799f..fec9c4387 100644 --- a/docs/introduction.asciidoc +++ b/docs/introduction.asciidoc @@ -27,12 +27,12 @@ npm install @elastic/elasticsearch The minimum supported version of Node.js is `v8`. -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 +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*] |=== |{es} Version |Client Version @@ -59,8 +59,8 @@ npm install @elastic/elasticsearch@ ==== Browser -WARNING: There is no official support for the browser environment. It exposes -your {es} instance to everyone, which could lead to security issues. We +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. @@ -82,13 +82,21 @@ You can use both the callback API and the promise API, both behave the same way. // 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) }) @@ -171,8 +179,8 @@ run().catch(console.log) ==== Install multiple versions -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 +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: @@ -218,12 +226,12 @@ client7.info(console.log) ---- -Finally, if you want to install the client for the next version of {es} (the one +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 installs the master branch of the client which is not +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 d83a2342d..1d60743a0 100644 --- a/docs/usage.asciidoc +++ b/docs/usage.asciidoc @@ -13,13 +13,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) }) @@ -52,13 +60,21 @@ options, and the connection that has been used. // 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) }) @@ -76,7 +92,11 @@ CAUTION: If you abort a request, the request will fail with a `RequestAbortedErr ---- const request = client.search({ index: 'my-index', - body: { foo: 'bar' } + body: { + query: { + match: { hello: 'world' } + } + } }, { ignore: [404], maxRetries: 3 @@ -96,7 +116,11 @@ The same behavior is valid for the promise style API as well. ---- const request = client.search({ index: 'my-index', - body: { foo: 'bar' } + body: { + query: { + match: { hello: 'world' } + } + } }, { ignore: [404], maxRetries: 3 @@ -118,16 +142,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