Skip to content

Commit d6577b7

Browse files
committed
Updated installation instructions (#835)
* Updated installation instructions * Added a note about Elasticsearch master
1 parent ddb72d6 commit d6577b7

File tree

1 file changed

+42
-15
lines changed

1 file changed

+42
-15
lines changed

docs/introduction.asciidoc

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,50 @@ The library is compatible with all Elasticsearch versions since 5.x, but you sho
3232
@elastic/elasticsearch@5
3333
----
3434

35-
=== Usage
35+
==== Install multiple versions
36+
If you are using multiple versions of Elasticsearch, you need to use multiple versions of the client. +
37+
In the past, install multiple versions of the same package was not possible, but with `npm v6.9`, you can do that via aliasing.
38+
39+
The command you must run to install different version of the client is:
40+
41+
[source,sh]
42+
----
43+
npm install <alias>@npm:@elastic/elasticsearch@<version>
44+
----
45+
46+
So for example if you need to install `7.x` and `6.x`, you will run
47+
[source,sh]
48+
----
49+
npm install es6@npm:@elastic/elasticsearch@6
50+
npm install es7@npm:@elastic/elasticsearch@7
51+
----
52+
53+
And your `package.json` will look like the following:
54+
[source,json]
55+
----
56+
"dependencies": {
57+
"es6": "npm:@elastic/elasticsearch@^6.7.0",
58+
"es7": "npm:@elastic/elasticsearch@^7.0.0"
59+
}
60+
----
61+
62+
And finally, you will require the packages from your code by using the alias you have defined.
63+
3664
[source,js]
3765
----
38-
const { Client } = require('@elastic/elasticsearch')
39-
const client = new Client({ node: 'http://localhost:9200' })
66+
const { Client: Client6 } = require('es6')
67+
const { Client: Client7 } = require('es7')
4068
41-
// promise API
42-
const result = await client.search({
43-
index: 'my-index',
44-
body: { foo: 'bar' }
45-
})
69+
const client6 = new Client6({ node: 'http://localhost:9200' })
70+
const client7 = new Client7({ node: 'http://localhost:9201' })
4671
47-
// callback API
48-
client.search({
49-
index: 'my-index',
50-
body: { foo: 'bar' }
51-
}, (err, result) => {
52-
if (err) console.log(err)
53-
})
72+
client6.info(console.log)
73+
client7.info(console.log)
74+
----
75+
76+
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:
77+
[source,sh]
78+
----
79+
npm install esmaster@github:elastic/elasticsearch-js
5480
----
81+
WARNING: This command will install the master branch of the client, which is not considered stable.

0 commit comments

Comments
 (0)