elastic-enterprise-search 0.3.1 → 7.10.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/.ci/.gitignore +1 -0
  3. data/.ci/Dockerfile +12 -0
  4. data/.ci/certs/README.md +50 -0
  5. data/.ci/certs/ca.crt +20 -0
  6. data/.ci/certs/ca.key +27 -0
  7. data/.ci/certs/testnode.crt +21 -0
  8. data/.ci/certs/testnode.key +27 -0
  9. data/.ci/certs/testnode_no_san.crt +19 -0
  10. data/.ci/certs/testnode_no_san.key +27 -0
  11. data/.ci/functions/cleanup.sh +67 -0
  12. data/.ci/functions/imports.sh +60 -0
  13. data/.ci/functions/wait-for-container.sh +36 -0
  14. data/.ci/jobs/defaults.yml +69 -0
  15. data/.ci/jobs/elastic+enterprise-search-ruby+master.yml +12 -0
  16. data/.ci/jobs/elastic+enterprise-search-ruby+pull-request.yml +19 -0
  17. data/.ci/run-elasticsearch.sh +127 -0
  18. data/.ci/run-enterprise-search.sh +70 -0
  19. data/.ci/run-local.sh +14 -0
  20. data/.ci/run-repository.sh +47 -0
  21. data/.ci/run-tests +29 -0
  22. data/.ci/test-matrix.yml +13 -0
  23. data/.github/workflows/rubocop.yml +15 -0
  24. data/.github/workflows/testing.yml +40 -0
  25. data/.gitignore +3 -0
  26. data/.rubocop.yml +52 -0
  27. data/Gemfile +22 -1
  28. data/{LICENSE.txt → LICENSE} +33 -32
  29. data/README.md +201 -103
  30. data/Rakefile +71 -1
  31. data/elastic-enterprise-search.gemspec +47 -13
  32. data/lib/elastic-enterprise-search.rb +20 -1
  33. data/lib/elastic/.rubocop.yml +6 -0
  34. data/lib/elastic/app-search/api/add_meta_engine_source.rb +48 -0
  35. data/lib/elastic/app-search/api/api_logs.rb +63 -0
  36. data/lib/elastic/app-search/api/count_analytics.rb +50 -0
  37. data/lib/elastic/app-search/api/create_curation.rb +52 -0
  38. data/lib/elastic/app-search/api/create_engine.rb +51 -0
  39. data/lib/elastic/app-search/api/create_synonym_set.rb +50 -0
  40. data/lib/elastic/app-search/api/curation.rb +52 -0
  41. data/lib/elastic/app-search/api/delete_curation.rb +52 -0
  42. data/lib/elastic/app-search/api/delete_documents.rb +48 -0
  43. data/lib/elastic/app-search/api/delete_engine.rb +48 -0
  44. data/lib/elastic/app-search/api/delete_meta_engine_source.rb +48 -0
  45. data/lib/elastic/app-search/api/delete_synonym_set.rb +52 -0
  46. data/lib/elastic/app-search/api/documents.rb +48 -0
  47. data/lib/elastic/app-search/api/engine.rb +48 -0
  48. data/lib/elastic/app-search/api/index_documents.rb +48 -0
  49. data/lib/elastic/app-search/api/list_curations.rb +50 -0
  50. data/lib/elastic/app-search/api/list_documents.rb +50 -0
  51. data/lib/elastic/app-search/api/list_engines.rb +47 -0
  52. data/lib/elastic/app-search/api/list_synonym_sets.rb +50 -0
  53. data/lib/elastic/app-search/api/log_clickthrough.rb +54 -0
  54. data/lib/elastic/app-search/api/multi_search.rb +50 -0
  55. data/lib/elastic/app-search/api/put_curation.rb +56 -0
  56. data/lib/elastic/app-search/api/put_documents.rb +48 -0
  57. data/lib/elastic/app-search/api/put_schema.rb +48 -0
  58. data/lib/elastic/app-search/api/put_search_settings.rb +48 -0
  59. data/lib/elastic/app-search/api/put_synonym_set.rb +54 -0
  60. data/lib/elastic/app-search/api/query_suggestion.rb +52 -0
  61. data/lib/elastic/app-search/api/reset_search_settings.rb +48 -0
  62. data/lib/elastic/app-search/api/schema.rb +48 -0
  63. data/lib/elastic/app-search/api/search.rb +48 -0
  64. data/lib/elastic/app-search/api/search_settings.rb +48 -0
  65. data/lib/elastic/app-search/api/synonym_set.rb +52 -0
  66. data/lib/elastic/app-search/api/top_clicks_analytics.rb +52 -0
  67. data/lib/elastic/app-search/api/top_queries_analytics.rb +51 -0
  68. data/lib/elastic/app-search/app_search.rb +65 -0
  69. data/lib/elastic/enterprise-search/api/health.rb +38 -0
  70. data/lib/elastic/enterprise-search/api/put_read_only.rb +40 -0
  71. data/lib/elastic/enterprise-search/api/read_only.rb +38 -0
  72. data/lib/elastic/enterprise-search/api/stats.rb +41 -0
  73. data/lib/elastic/enterprise-search/api/version.rb +38 -0
  74. data/lib/elastic/enterprise-search/client.rb +79 -15
  75. data/lib/elastic/enterprise-search/configuration.rb +32 -16
  76. data/lib/elastic/enterprise-search/exceptions.rb +19 -0
  77. data/lib/elastic/enterprise-search/request.rb +46 -80
  78. data/lib/elastic/enterprise-search/utils.rb +29 -1
  79. data/lib/elastic/enterprise-search/version.rb +20 -1
  80. data/lib/elastic/enterprise_search.rb +38 -0
  81. data/lib/elastic/workplace-search/api/add_user_permissions.rb +53 -0
  82. data/lib/elastic/workplace-search/api/create_external_identity.rb +49 -0
  83. data/lib/elastic/workplace-search/api/delete_documents.rb +49 -0
  84. data/lib/elastic/workplace-search/api/delete_external_identity.rb +49 -0
  85. data/lib/elastic/workplace-search/api/external_identity.rb +49 -0
  86. data/lib/elastic/workplace-search/api/index_documents.rb +49 -0
  87. data/lib/elastic/workplace-search/api/list_external_identities.rb +47 -0
  88. data/lib/elastic/workplace-search/api/list_permissions.rb +47 -0
  89. data/lib/elastic/workplace-search/api/put_external_identity.rb +53 -0
  90. data/lib/elastic/workplace-search/api/put_user_permissions.rb +53 -0
  91. data/lib/elastic/workplace-search/api/remove_user_permissions.rb +53 -0
  92. data/lib/elastic/workplace-search/api/search.rb +42 -0
  93. data/lib/elastic/workplace-search/api/user_permissions.rb +49 -0
  94. data/lib/elastic/workplace-search/workplace_search.rb +59 -0
  95. data/lib/generator/documentation_helper.rb +94 -0
  96. data/lib/generator/endpoint_generator.rb +119 -0
  97. data/lib/generator/parameters_exceptions.rb +40 -0
  98. data/lib/generator/parameters_helper.rb +144 -0
  99. data/lib/generator/templates/_license.erb +16 -0
  100. data/lib/generator/templates/endpoint_template.erb +29 -0
  101. data/lib/generator/templates/spec_template.erb +1 -0
  102. data/lib/generator/utils.rb +70 -0
  103. data/spec/app-search/api_count_analytics_spec.rb +34 -0
  104. data/spec/app-search/api_documents_spec.rb +88 -0
  105. data/spec/app-search/api_engines_spec.rb +67 -0
  106. data/spec/app-search/api_logs_spec.rb +36 -0
  107. data/spec/app-search/api_schema_spec.rb +34 -0
  108. data/spec/app-search/api_search_and_multi_search_spec.rb +48 -0
  109. data/spec/app-search/api_spec_helper.rb +14 -0
  110. data/spec/app-search/api_top_clicks_analytics_spec.rb +44 -0
  111. data/spec/app-search/api_top_queries_analytics_spec.rb +34 -0
  112. data/spec/app-search/client_spec.rb +68 -0
  113. data/spec/enterprise-search/client_spec.rb +96 -0
  114. data/spec/enterprise-search/request_spec.rb +114 -0
  115. data/spec/fixtures/vcr/add_user_permissions.yml +18 -22
  116. data/spec/fixtures/vcr/app_search/api_logs.yml +70 -0
  117. data/spec/fixtures/vcr/app_search/api_top_clicks_analytics.yml +55 -0
  118. data/spec/fixtures/vcr/app_search/api_top_clicks_analytics_query.yml +55 -0
  119. data/spec/fixtures/vcr/app_search/api_top_queries_analytics.yml +55 -0
  120. data/spec/fixtures/vcr/app_search/count_analytics.yml +55 -0
  121. data/spec/fixtures/vcr/app_search/create_and_update_document.yml +107 -0
  122. data/spec/fixtures/vcr/app_search/index_and_delete_document.yml +107 -0
  123. data/spec/fixtures/vcr/app_search/index_documents.yml +56 -0
  124. data/spec/fixtures/vcr/app_search/list_documents.yml +57 -0
  125. data/spec/fixtures/vcr/app_search/multi_query_search.yml +63 -0
  126. data/spec/fixtures/vcr/app_search/schema.yml +55 -0
  127. data/spec/fixtures/vcr/app_search/search.yml +57 -0
  128. data/spec/fixtures/vcr/app_search/single_query_search.yml +60 -0
  129. data/spec/fixtures/vcr/clear_user_permissions.yml +51 -0
  130. data/spec/fixtures/vcr/create_document.yml +54 -0
  131. data/spec/fixtures/vcr/create_engine.yml +55 -0
  132. data/spec/fixtures/vcr/delete_documents.yml +51 -0
  133. data/spec/fixtures/vcr/delete_engine.yml +55 -0
  134. data/spec/fixtures/vcr/get_engine.yml +55 -0
  135. data/spec/fixtures/vcr/index_documents.yml +53 -0
  136. data/spec/fixtures/vcr/list_engines.yml +55 -0
  137. data/spec/fixtures/vcr/list_permissions.yml +51 -0
  138. data/spec/fixtures/vcr/put_user_permissions.yml +99 -0
  139. data/spec/fixtures/vcr/remove_user_permissions.yml +16 -20
  140. data/spec/fixtures/vcr/user_permissions_empty.yml +51 -0
  141. data/spec/integration/enterprise_search_api_spec.rb +96 -0
  142. data/spec/spec_helper.rb +25 -14
  143. data/spec/webmock_requires.rb +4 -0
  144. data/spec/workplace-search/api_spec.rb +188 -0
  145. data/spec/workplace-search/client_spec.rb +69 -0
  146. metadata +207 -47
  147. data/.circleci/config.yml +0 -68
  148. data/.travis.yml +0 -15
  149. data/NOTICE.txt +0 -3
  150. data/lib/elastic/enterprise-search.rb +0 -7
  151. data/lib/elastic/enterprise-search/client/content_source_documents.rb +0 -46
  152. data/lib/elastic/enterprise-search/client/permissions.rb +0 -30
  153. data/logo-enterprise-search.png +0 -0
  154. data/spec/client/content_source_documents_spec.rb +0 -55
  155. data/spec/client/permissions_spec.rb +0 -75
  156. data/spec/configuration_spec.rb +0 -19
  157. data/spec/fixtures/vcr/async_create_or_update_document_success.yml +0 -51
  158. data/spec/fixtures/vcr/destroy_documents_success.yml +0 -51
  159. data/spec/fixtures/vcr/get_user_permissions.yml +0 -55
  160. data/spec/fixtures/vcr/list_all_permissions.yml +0 -55
  161. data/spec/fixtures/vcr/list_all_permissions_with_paging.yml +0 -55
  162. data/spec/fixtures/vcr/update_user_permissions.yml +0 -55
data/Gemfile CHANGED
@@ -1,4 +1,25 @@
1
- source "https://rubygems.org"
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ # frozen_string_literal: true
19
+
20
+ source 'https://rubygems.org'
2
21
 
3
22
  # Specify your gem's dependencies in elastic-enterprise-search.gemspec
4
23
  gemspec
24
+
25
+ gem 'rake'
@@ -1,18 +1,19 @@
1
+
1
2
  Apache License
2
3
  Version 2.0, January 2004
3
4
  http://www.apache.org/licenses/
4
5
 
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
7
 
7
- 1. Definitions.
8
+ 1. Definitions.
8
9
 
9
- "License" shall mean the terms and conditions for use, reproduction,
10
+ "License" shall mean the terms and conditions for use, reproduction,
10
11
  and distribution as defined by Sections 1 through 9 of this document.
11
12
 
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
+ "Licensor" shall mean the copyright owner or entity authorized by
13
14
  the copyright owner that is granting the License.
14
15
 
15
- "Legal Entity" shall mean the union of the acting entity and all
16
+ "Legal Entity" shall mean the union of the acting entity and all
16
17
  other entities that control, are controlled by, or are under common
17
18
  control with that entity. For the purposes of this definition,
18
19
  "control" means (i) the power, direct or indirect, to cause the
@@ -20,24 +21,24 @@
20
21
  otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
22
  outstanding shares, or (iii) beneficial ownership of such entity.
22
23
 
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
+ "You" (or "Your") shall mean an individual or Legal Entity
24
25
  exercising permissions granted by this License.
25
26
 
26
- "Source" form shall mean the preferred form for making modifications,
27
+ "Source" form shall mean the preferred form for making modifications,
27
28
  including but not limited to software source code, documentation
28
29
  source, and configuration files.
29
30
 
30
- "Object" form shall mean any form resulting from mechanical
31
+ "Object" form shall mean any form resulting from mechanical
31
32
  transformation or translation of a Source form, including but
32
33
  not limited to compiled object code, generated documentation,
33
34
  and conversions to other media types.
34
35
 
35
- "Work" shall mean the work of authorship, whether in Source or
36
+ "Work" shall mean the work of authorship, whether in Source or
36
37
  Object form, made available under the License, as indicated by a
37
38
  copyright notice that is included in or attached to the work
38
39
  (an example is provided in the Appendix below).
39
40
 
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
+ "Derivative Works" shall mean any work, whether in Source or Object
41
42
  form, that is based on (or derived from) the Work and for which the
42
43
  editorial revisions, annotations, elaborations, or other modifications
43
44
  represent, as a whole, an original work of authorship. For the purposes
@@ -45,7 +46,7 @@
45
46
  separable from, or merely link (or bind by name) to the interfaces of,
46
47
  the Work and Derivative Works thereof.
47
48
 
48
- "Contribution" shall mean any work of authorship, including
49
+ "Contribution" shall mean any work of authorship, including
49
50
  the original version of the Work and any modifications or additions
50
51
  to that Work or Derivative Works thereof, that is intentionally
51
52
  submitted to Licensor for inclusion in the Work by the copyright owner
@@ -59,18 +60,18 @@
59
60
  excluding communication that is conspicuously marked or otherwise
60
61
  designated in writing by the copyright owner as "Not a Contribution."
61
62
 
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
64
  on behalf of whom a Contribution has been received by Licensor and
64
65
  subsequently incorporated within the Work.
65
66
 
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
68
  this License, each Contributor hereby grants to You a perpetual,
68
69
  worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
70
  copyright license to reproduce, prepare Derivative Works of,
70
71
  publicly display, publicly perform, sublicense, and distribute the
71
72
  Work and such Derivative Works in Source or Object form.
72
73
 
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
75
  this License, each Contributor hereby grants to You a perpetual,
75
76
  worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
77
  (except as stated in this section) patent license to make, have made,
@@ -86,24 +87,24 @@
86
87
  granted to You under this License for that Work shall terminate
87
88
  as of the date such litigation is filed.
88
89
 
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
+ 4. Redistribution. You may reproduce and distribute copies of the
90
91
  Work or Derivative Works thereof in any medium, with or without
91
92
  modifications, and in Source or Object form, provided that You
92
93
  meet the following conditions:
93
94
 
94
- (a) You must give any other recipients of the Work or
95
+ (a) You must give any other recipients of the Work or
95
96
  Derivative Works a copy of this License; and
96
97
 
97
- (b) You must cause any modified files to carry prominent notices
98
+ (b) You must cause any modified files to carry prominent notices
98
99
  stating that You changed the files; and
99
100
 
100
- (c) You must retain, in the Source form of any Derivative Works
101
+ (c) You must retain, in the Source form of any Derivative Works
101
102
  that You distribute, all copyright, patent, trademark, and
102
103
  attribution notices from the Source form of the Work,
103
104
  excluding those notices that do not pertain to any part of
104
105
  the Derivative Works; and
105
106
 
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
+ (d) If the Work includes a "NOTICE" text file as part of its
107
108
  distribution, then any Derivative Works that You distribute must
108
109
  include a readable copy of the attribution notices contained
109
110
  within such NOTICE file, excluding those notices that do not
@@ -120,14 +121,14 @@
120
121
  that such additional attribution notices cannot be construed
121
122
  as modifying the License.
122
123
 
123
- You may add Your own copyright statement to Your modifications and
124
+ You may add Your own copyright statement to Your modifications and
124
125
  may provide additional or different license terms and conditions
125
126
  for use, reproduction, or distribution of Your modifications, or
126
127
  for any such Derivative Works as a whole, provided Your use,
127
128
  reproduction, and distribution of the Work otherwise complies with
128
129
  the conditions stated in this License.
129
130
 
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
132
  any Contribution intentionally submitted for inclusion in the Work
132
133
  by You to the Licensor shall be under the terms and conditions of
133
134
  this License, without any additional terms or conditions.
@@ -135,12 +136,12 @@
135
136
  the terms of any separate license agreement you may have executed
136
137
  with Licensor regarding such Contributions.
137
138
 
138
- 6. Trademarks. This License does not grant permission to use the trade
139
+ 6. Trademarks. This License does not grant permission to use the trade
139
140
  names, trademarks, service marks, or product names of the Licensor,
140
141
  except as required for reasonable and customary use in describing the
141
142
  origin of the Work and reproducing the content of the NOTICE file.
142
143
 
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
145
  agreed to in writing, Licensor provides the Work (and each
145
146
  Contributor provides its Contributions) on an "AS IS" BASIS,
146
147
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
@@ -150,7 +151,7 @@
150
151
  appropriateness of using or redistributing the Work and assume any
151
152
  risks associated with Your exercise of permissions under this License.
152
153
 
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
+ 8. Limitation of Liability. In no event and under no legal theory,
154
155
  whether in tort (including negligence), contract, or otherwise,
155
156
  unless required by applicable law (such as deliberate and grossly
156
157
  negligent acts) or agreed to in writing, shall any Contributor be
@@ -162,7 +163,7 @@
162
163
  other commercial damages or losses), even if such Contributor
163
164
  has been advised of the possibility of such damages.
164
165
 
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
167
  the Work or Derivative Works thereof, You may choose to offer,
167
168
  and charge a fee for, acceptance of support, warranty, indemnity,
168
169
  or other liability obligations and/or rights consistent with this
@@ -173,11 +174,11 @@
173
174
  incurred by, or claims asserted against, such Contributor by reason
174
175
  of your accepting any such warranty or additional liability.
175
176
 
176
- END OF TERMS AND CONDITIONS
177
+ END OF TERMS AND CONDITIONS
177
178
 
178
- APPENDIX: How to apply the Apache License to your work.
179
+ APPENDIX: How to apply the Apache License to your work.
179
180
 
180
- To apply the Apache License to your work, attach the following
181
+ To apply the Apache License to your work, attach the following
181
182
  boilerplate notice, with the fields enclosed by brackets "[]"
182
183
  replaced with your own identifying information. (Don't include
183
184
  the brackets!) The text should be enclosed in the appropriate
@@ -186,15 +187,15 @@
186
187
  same "printed page" as the copyright notice for easier
187
188
  identification within third-party archives.
188
189
 
189
- Copyright 2019 Elasticsearch B.V.
190
+ Copyright [yyyy] [name of copyright owner]
190
191
 
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
+ Licensed under the Apache License, Version 2.0 (the "License");
192
193
  you may not use this file except in compliance with the License.
193
194
  You may obtain a copy of the License at
194
195
 
195
- http://www.apache.org/licenses/LICENSE-2.0
196
+ http://www.apache.org/licenses/LICENSE-2.0
196
197
 
197
- Unless required by applicable law or agreed to in writing, software
198
+ Unless required by applicable law or agreed to in writing, software
198
199
  distributed under the License is distributed on an "AS IS" BASIS,
199
200
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
201
  See the License for the specific language governing permissions and
data/README.md CHANGED
@@ -1,173 +1,271 @@
1
- <p align="center"><img src="https://github.com/elastic/enterprise-search-ruby/blob/master/logo-enterprise-search.png?raw=true" alt="Elastic Enterprise Search Logo"></p>
1
+ # Elastic Enterprise Search Client
2
2
 
3
- <p align="center"><a href="https://circleci.com/gh/elastic/enterprise-search-ruby"><img src="https://circleci.com/gh/elastic/enterprise-search-ruby.svg?style=svg" alt="CircleCI build"></a></p>
3
+ ![build](https://github.com/elastic/enterprise-search-ruby/workflows/master/badge.svg)
4
+ ![rubocop](https://github.com/elastic/enterprise-search-ruby/workflows/rubocop/badge.svg)
5
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop-hq/rubocop)
4
6
 
5
- > A first-party Ruby client for [Elastic Enterprise Search](https://www.elastic.co/solutions/enterprise-search).
7
+ This project is in development and in a beta state.
6
8
 
7
9
  ## Contents
10
+ - [Installation](https://github.com/elastic/enterprise-search-ruby#installation)
11
+ - [Getting Started](https://github.com/elastic/enterprise-search-ruby#getting-started)
12
+ - [Enterprise Search](https://github.com/elastic/enterprise-search-ruby#enterprise-search)
13
+ - [Workplace Search](https://github.com/elastic/enterprise-search-ruby#workplace-search)
14
+ - [App Search](https://github.com/elastic/enterprise-search-ruby#app-search)
15
+ - [HTTP Layer](https://github.com/elastic/enterprise-search-ruby#http-layer)
16
+ - [Setting the host and port](https://github.com/elastic/enterprise-search-ruby#setting-the-host-and-port)
17
+ - [Logging](https://github.com/elastic/enterprise-search-ruby#logging)
18
+ - [Development](https://github.com/elastic/enterprise-search-ruby#development)
19
+ - [Run stack locally](https://github.com/elastic/enterprise-search-ruby#run-stack-locally)
20
+ - [Run tests](https://github.com/elastic/enterprise-search-ruby#run-tests)
21
+ - [License](https://github.com/elastic/enterprise-search-ruby#license)
22
+
23
+ ## Installation
24
+
25
+ Install the gem:
8
26
 
9
- + [Getting started](#getting-started-)
10
- + [Usage](#usage)
11
- + [FAQ](#faq-)
12
- + [Contribute](#contribute-)
13
- + [License](#license-)
27
+ ```
28
+ $ gem install elastic-enterprise-search --pre
29
+ ```
14
30
 
15
- ***
31
+ Or add it to your project's Gemfile:
16
32
 
17
- ## Getting started 🐣
33
+ ```
34
+ gem 'elastic-enterprise-search'
35
+ ```
18
36
 
19
- To install the gem, execute:
37
+ The version follows the Elastic Stack version so 7.10.0 is compatible with Enterprise Search released in Elastic Stack 7.10.0.
20
38
 
21
- ```bash
22
- gem install elastic-enterprise-search
23
- ```
39
+ ## Getting Started
24
40
 
25
- Or place `gem 'elastic-enterprise-search', '~> 0.3.1` in your `Gemfile` and run `bundle install`.
41
+ ### Enterprise Search
26
42
 
27
- ## Usage
43
+ The Enterprise Search API uses basic auth with credentials from an Elasticsearch user. You can read about the API, authentication and privileges needed [on the official docs](https://www.elastic.co/guide/en/enterprise-search/current/management-apis.html).
28
44
 
29
- Create a new instance of the Enterprise Search Client with your access token:
45
+ #### Example usage:
30
46
 
31
47
  ```ruby
32
- Elastic::EnterpriseSearch.access_token = '' # your access token
33
- client = Elastic::EnterpriseSearch::Client.new
48
+ http_auth = {user: 'elastic', password: 'password'}
49
+ host = 'https://id.ent-search.europe-west2.gcp.elastic-cloud.com'
50
+
51
+ ent_client = Elastic::EnterpriseSearch::Client.new(host: host, http_auth: http_auth)
34
52
  ```
35
53
 
36
- ### Change API endpoint
54
+ #### Health API
37
55
 
38
56
  ```ruby
39
- client = Elastic::EnterpriseSearch::Client.new
40
- Elastic::EnterpriseSearch.endpoint = 'https://your-server.example.com/api/v1'
57
+ > response = ent_client.health
58
+ > response.body
59
+ => {"name"=>"...",
60
+ "version"=>{"number"=>"7.10.0", "build_hash"=>"...", "build_date"=>"..."},
61
+ "jvm"=>{...},
62
+ "filebeat"=>{...},
63
+ "system"=>{...}
64
+ }
41
65
  ```
42
66
 
43
- ### Specifying an HTTP Proxy
67
+ #### Version API
44
68
 
45
69
  ```ruby
46
- client = Elastic::EnterpriseSearch::Client.new(:proxy => 'http://localhost:8888')
70
+ > response = ent_client.version
71
+ > response.body
72
+ => {"number"=>"7.10.0", "build_hash"=>"...", "build_date"=>"..."}
47
73
  ```
48
74
 
49
- ### Documents
50
-
51
- #### Indexing Documents
52
-
53
- This example shows how to use the index_documents method:
75
+ #### Managing Read-Only mode:
54
76
 
55
77
  ```ruby
56
- content_source_key = '' # your content source key
57
- documents = [
58
- {
59
- 'id' => 'INscMGmhmX4',
60
- 'url' => 'http://www.youtube.com/watch?v=v1uyQZNg2vE',
61
- 'title' => 'The Original Grumpy Cat',
62
- 'body' => 'this is a test'
63
- },
64
- {
65
- 'id' => 'JNDFojsd02',
66
- 'url' => 'http://www.youtube.com/watch?v=tsdfhk2j',
67
- 'title' => 'Another Grumpy Cat',
68
- 'body' => 'this is also a test'
69
- }
70
- ]
71
-
72
- begin
73
- document_receipts = client.index_documents(content_source_key, documents)
74
- # handle results
75
- rescue Elastic::EnterpriseSearch::ClientException => e
76
- # handle error
77
- end
78
- ```
79
-
80
- #### Destroying Documents
78
+ # Set read-only flag state
79
+ ent_client.put_read_only(enabled: false)
80
+
81
+ # Get read-only flag state
82
+ ent_client.read_only
83
+ ```
81
84
 
85
+ #### Stats API
82
86
  ```ruby
83
- content_source_key = '' # your content source key
84
- document_ids = ['INscMGmhmX4', 'JNDFojsd02']
87
+ > ent_client.stats.body
88
+ => {"app"=>{"pid"=>1, "start"=>"...", "end"=>"", "metrics"=>{...}},
89
+ "queues"=>{"connectors"=>{...}, "document_destroyer"=>{...}, "engine_destroyer"=>{...}, "index_adder"=>{...}, ...},
90
+ "connectors"=>{"alive"=>true, "pool"=>{...}, "job_store"=>{...}}}}
85
91
 
86
- begin
87
- destroy_document_results = client.destroy_documents(content_source_key, document_ids)
88
- # handle destroy document results
89
- rescue Elastic::EnterpriseSearch::ClientException => e
90
- # handle error
91
- end
92
92
  ```
93
93
 
94
- ### Permissions
94
+ ### Workplace Search
95
95
 
96
- #### Listing all permissions
96
+ In your Elastic Workplace Search dashboard navigate to _Sources/Add a Shared Content Source_ and select _Custom API Source_ to create a new source. Name your source (e.g. `Enterprise Search Ruby Client`) and once it's created you'll get an `access token` and a `key`. You'll need these in the following steps.
97
97
 
98
- ```ruby
99
- content_source_key = '' # your content source key
98
+ #### Instantiation
99
+
100
+ The Workplace Search client can be accessed from an existing Enterprise Search Client, or you can initialize a new one. If you instantiate the Workplace Search client from an existing Enterprise Search Client, it's going to share the HTTP transport instance, so it's going to connect to the same host, which is a common scenario. However, if you want to connect to a different host, you should instantiate a new Workplace Client on its own:
100
101
 
101
- client.list_all_permissions(content_source_key)
102
+ ```ruby
103
+ # Prerequisites
104
+ host = 'https://id.ent-search.europe-west2.gcp.elastic-cloud.com'
105
+ access_token = '<access token>'
106
+ content_source_key = '<content source key>'
107
+
108
+ # From the Enterprise Search client:
109
+ ent_client = Elastic::EnterpriseSearch::Client.new(host: host)
110
+ ent_client.workplace_search.http_auth = access_token
111
+ ent_client.workplace_search.index_documents(content_source_key, body: documents)
112
+
113
+ # On its own
114
+ workplace_search_client = Elastic::EnterpriseSearch::WorkplaceSearch::Client.new(
115
+ host: host,
116
+ http_auth: access_token
117
+ )
102
118
  ```
103
119
 
104
- #### Listing all permissions with paging
120
+ ### App Search
121
+
122
+ In your Elastic App Search dashboard, navigate to Credentials and Create a Key for the client to use. Make sure to read [the documentation on Authentication](https://www.elastic.co/guide/en/app-search/current/authentication.html) to understand which key you want to use. Once you've created your key, you need to copy the key value to use on your client:
123
+
124
+ #### Instantiation
125
+
126
+ The App Search client can be accessed from an existing Enterprise Search Client, or you can initialize a new one. If you instantiate the App Search client from an existing Enterprise Search Client, it's going to share the HTTP transport instance, so it's going to connect to the same host which is a common scenario. However, if you want to connect to a different host, you should instantiate a new App Search Client on its own.
105
127
 
106
128
  ```ruby
107
- content_source_key = '' # your content source key
129
+ # Prerequisites
130
+ host = 'https://id.ent-search.europe-west2.gcp.elastic-cloud.com'
131
+ api_key = 'private-api-key'
108
132
 
109
- client.list_all_permissions(content_source_key, :current => 2, :size => 20)
133
+ # From the Enterprise Search client:
134
+ ent_client = Elastic::EnterpriseSearch::Client.new(host: host)
135
+ ent_client.app_search.http_auth = api_key
136
+
137
+ # On its own
138
+ client = Elastic::EnterpriseSearch::AppSearch::Client.new(host: host, http_auth: api_key)
110
139
  ```
111
140
 
112
- #### Retrieve a User's permissions
141
+ #### Engines
113
142
 
114
143
  ```ruby
115
- content_source_key = '' # your content source key
116
- user = 'enterprise_search'
144
+ # Create an engine
145
+ client.create_engine(name: 'videogames')
146
+
147
+ # List all engines
148
+ client.list_engines
149
+
150
+ # Get an engine
151
+ client.engine('videogames')
117
152
 
118
- client.get_user_permissions(content_source_key, user)
153
+ # Delete an engine
154
+ client.delete_engine('videogames')
119
155
  ```
120
156
 
121
- #### Add permissions to a User
157
+ #### Documents
158
+
122
159
  ```ruby
123
- content_source_key = '' # your content source key
124
- user = 'enterprise_search'
125
- permissions = ['permission1']
160
+ engine_name = 'videogames'
161
+ document = {
162
+ id: 'Mr1064',
163
+ name: 'Super Luigi 64',
164
+ body: 'A classic 3D videogame'
165
+ }
166
+
167
+ # Index documents
168
+ client.index_documents(engine_name, body: document)
169
+
170
+ # List documents
171
+ client.list_documents(engine_name)
126
172
 
127
- client.add_user_permissions(content_source_key, user, :permissions => permissions)
173
+ # Delete a document
174
+ client.delete_documents(engine_name, body: [document_id])
175
+
176
+ # Update a document
177
+ client.put_documents(engine_name, body: [{id: document_id, key: value}])
128
178
  ```
129
179
 
130
- #### Update a User's permissions
180
+ #### Search
181
+
131
182
  ```ruby
132
- content_source_key = '' # your content source key
133
- user = 'enterprise_search'
134
- permissions = ['permission2']
183
+ query = {
184
+ query: 'luigi'
185
+ }
135
186
 
136
- client.update_user_permissions(content_source_key, user, :permissions => permissions)
187
+ client.search(engine_name, query)
137
188
  ```
138
189
 
139
- #### Remove permissions from a User
190
+ #### Other API Endpoints
191
+
140
192
  ```ruby
141
- content_source_key = '' # your content source key
142
- user = 'enterprise_search'
143
- permissions = ['permission2']
144
193
 
145
- client.remove_user_permissions(content_source_key, user, :permissions => permissions)
194
+ # Count analytics - Returns the number of clicks and total number of queries over a period
195
+ client.count_analytics(engine_name)
196
+
197
+ # Schema - Retrieve current schema for the engine
198
+ client.schema(engine_name)
199
+
200
+ # Logs - The API Log displays API request and response data at the Engine level
201
+ client.api_logs(engine_name, from_date: Date.new(2020, 10, 01), to_date: Date.new(2020, 11, 05))
202
+
203
+ # Queries Analytics - Returns queries analytics by usage count
204
+ client.top_queries_analytics(engine_name)
205
+
206
+ # Clicks Analytics - Returns the number of clicks received by a document in descending order
207
+ client.top_clicks_analytics(engine_name, query: {})
208
+
146
209
  ```
147
210
 
148
- ## Running tests
211
+ ## HTTP Layer
212
+
213
+ This library uses [elasticsearch-transport](https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-transport), the low-level Ruby client for connecting to an Elasticsearch cluster - also used in the official [Elasticsearch Ruby Client](https://github.com/elastic/elasticsearch-ruby).
214
+
215
+ All requests, if successful, will return an `Elasticsearch::Transport::Transport::Response` instance. You can access the response `body`, `headers` and `status`.
216
+
217
+ `elasticsearch-transport` defines a [number of exception classes](https://github.com/elasticsearch/elasticsearch-ruby/blob/master/elasticsearch-transport/lib/elasticsearch/transport/transport/errors.rb) for various client and server errors, as well as unsuccessful HTTP responses, making it possible to rescue specific exceptions with desired granularity. More details [here](https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-transport#exception-handling). You can find the full documentation for `elasticsearch-transport` at [RubyDoc](https://rubydoc.info/gems/elasticsearch-transport).
218
+
219
+ The clients pass different options to transport, you can check them out [in the source code](https://github.com/elastic/enterprise-search-ruby/blob/master/lib/elastic/enterprise-search/client.rb) while we set up RubyDocs.
220
+
221
+ ### Setting the host and port
222
+
223
+ If you don't specify a host and port, the client will default to `http://localhost:3002`. Otherwise pass in the `:host` parameter as a String.
224
+
225
+ ### Logging
149
226
 
150
- Run tests via rspec:
227
+ You can enable logging with the default logger by passing `log: true` as a parameter to the client's initializer, or pass in a Logger object with the `:logger` parameter:
151
228
 
152
- ```bash
153
- $ ENDPOINT=http://localhost:3002/api/v1 bundle exec rspec
229
+ ```ruby
230
+ logger = MyLogger.new
231
+ client = Elastic::EnterpriseSearch::Client.new(logger: logger)
154
232
  ```
155
233
 
156
- ## FAQ 🔮
234
+ ## Development
235
+
236
+ ### Run Stack locally
237
+
238
+ A rake task is included to run the Elastic Enterprise Search stack locally via Docker:
239
+
240
+ ```
241
+ $ rake stack[7.10.0]
242
+ ```
157
243
 
158
- ### Where do I report issues with the client?
244
+ This will run Elastic Enterprise Search in http://localhost:3002
245
+ - Username: `enterprise_search`
246
+ - Password: `changeme`
159
247
 
160
- If something is not working as expected, please open an [issue](https://github.com/elastic/enterprise-search-ruby/issues/new).
248
+ ### Run Tests
161
249
 
162
- ## Contribute 🚀
250
+ Unit tests for the clients:
163
251
 
164
- We welcome contributors to the project. Before you begin, a couple notes...
252
+ ```
253
+ $ rake spec:client
254
+ ```
165
255
 
166
- + Before opening a pull request, please create an issue to [discuss the scope of your proposal](https://github.com/elastic/enterprise-search-ruby/issues).
167
- + Please write simple code and concise documentation, when appropriate.
256
+ Integration tests: you need to have an instance of Enterprise Search running either locally or remotely, and specify the host and credentials in environment variables (see below for a complete dockerized setup). If you're using the included rake task `rake stack[:version]`, you can run the integration tests with the following command:
257
+ ```
258
+ $ ELASTIC_ENTERPRISE_HOST='http://localhost:3002' \
259
+ ELASTIC_ENTERPRISE_USER='elastic' \
260
+ ELASTIC_ENTERPRISE_PASSWORD='changeme' \
261
+ rake spec:integration
262
+ ```
168
263
 
169
- ## License 📗
264
+ Run integration tests completely within containers, the way we run them on our CI:
265
+ ```
266
+ RUNSCRIPTS=enterprise-search STACK_VERSION=7.10.0 ./.ci/run-tests
267
+ ```
170
268
 
171
- [Apache 2.0](https://github.com/elastic/enterprise-search-ruby/blob/master/LICENSE.txt) © [Elastic](https://github.com/elastic)
269
+ ## License
172
270
 
173
- Thank you to all the [contributors](https://github.com/elastic/enterprise-search-ruby/graphs/contributors)!
271
+ Apache-2.0