@@ -13,7 +13,6 @@ The full documentation is available on https://metacpan.org/module/Search::Elast
13
13
* Good defaults
14
14
* Helper utilities for more complex operations, such as bulk indexing, scrolled searches and reindexing.
15
15
* Logging support via ` Log::Any `
16
- * Compatibility with the [ official clients] ( https://www.elastic.co/guide/en/elasticsearch/client/index.html )
17
16
* Easy extensibility
18
17
19
18
## Install
@@ -22,6 +21,83 @@ The full documentation is available on https://metacpan.org/module/Search::Elast
22
21
cpanm Search::Elasticsearch
23
22
```
24
23
24
+ ## Connecting to Elasticsearch
25
+
26
+ You can connect to Elasticsearch using the following examples:
27
+
28
+ ``` perl
29
+ use Search::Elasticsearch;
30
+
31
+ # Connect to localhost:9200 (default)
32
+ my $e = Search::Elasticsearch-> new();
33
+
34
+ # Connect to http://search:9200
35
+ my $e = Search::Elasticsearch-> new(
36
+ nodes => [ ' search:9200' ]
37
+ );
38
+
39
+ # Round-robin between two nodes:
40
+ my $e = Search::Elasticsearch-> new(
41
+ nodes => [
42
+ ' search1:9200' ,
43
+ ' search2:9200'
44
+ ]
45
+ );
46
+ ```
47
+
48
+ After the connection you can start using the Elaticsearch endpoints
49
+ as functions of ` $e ` object, as follows:
50
+
51
+ ``` perl
52
+ # Info endpoint
53
+ my $result = $e -> info();
54
+
55
+ printf (" Name: %s \n " , $result -> {name }); # e.g. Name: instance-001
56
+ printf (" Version: %s \n " , $result -> {version }-> {number }); # e.g. Version: 8.5.2
57
+ ```
58
+
59
+ ## Connecting to Elastic Cloud
60
+
61
+ [ Elastic Cloud] ( https://www.elastic.co/cloud/ ) is the cloud solution offered by Elastic.
62
+
63
+ To connect the Perl client to Elastic Cloud you need the get the following data:
64
+
65
+ - the Elasticsearch server address (i.e. public URL);
66
+ - the Elastic Cloud API key;
67
+
68
+ You can retrieve these data from your Elastic Cloud dashboard. You need to open the
69
+ ** Manage Deployments** page and ** Copy endpoint of Elasticsearch** (see screenshot below).
70
+
71
+ ![ Endpoint] ( docs/images/copy_endpoint.png )
72
+
73
+ This endpoint is the server address of Test instance (e.g. https://my-test.es.us-central1.gcp.cloud.es.io ).
74
+
75
+ After this step, you need to generate an ` API key ` in the ` Management ` page under the section ` Security ` .
76
+
77
+ ![ Security] ( docs/images/create_api_key.png )
78
+
79
+ When you click on ` Create API key ` button you can choose a name and set the
80
+ other options (for example, restrict privileges, expire after time, and so on).
81
+
82
+ ![ Choose an API name] ( docs/images/api_key_name.png )
83
+
84
+ After this step you will get the ` API key ` in the API keys page.
85
+
86
+ ![ API key] ( docs/images/cloud_api_key.png )
87
+
88
+ ** IMPORTANT** : you need to copy and store the ` API key ` in a secure place, since
89
+ you will not be able to view it again in Elastic Cloud.
90
+
91
+ Finally, you can use the Elasticsearch endpoint and the API Key for connecting
92
+ the Perl client as follows:
93
+
94
+ ``` perl
95
+ my $e = Search::Elasticsearch-> new(
96
+ nodes => [ ' https://my-test.es.us-central1.gcp.cloud.es.io' ],
97
+ elastic_cloud_api_key => ' insert here the API Key'
98
+ );
99
+ ```
100
+
25
101
## Compatibility
26
102
27
103
Language clients are forward compatible; meaning that clients support communicating
0 commit comments