elastic-enterprise-search 7.10.0.beta.1 → 7.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ci/jobs/elastic+enterprise-search-ruby+7.10.0.beta.1.yml +12 -0
- data/.ci/test-matrix.yml +2 -1
- data/.github/workflows/testing.yml +1 -1
- data/.gitignore +1 -0
- data/CONTRIBUTING.md +43 -0
- data/Gemfile +1 -0
- data/README.md +7 -225
- data/Rakefile +1 -24
- data/docs/guide/app-search-api.asciidoc +172 -0
- data/docs/guide/connecting.asciidoc +125 -0
- data/docs/guide/development.asciidoc +42 -0
- data/docs/guide/enterprise-search-api.asciidoc +46 -0
- data/docs/guide/index.asciidoc +17 -0
- data/docs/guide/installation.asciidoc +18 -0
- data/docs/guide/overview.asciidoc +59 -0
- data/docs/guide/workplace-search-api.asciidoc +121 -0
- data/elastic-enterprise-search.gemspec +5 -4
- data/lib/elastic/app-search/api/add_meta_engine_source.rb +7 -4
- data/lib/elastic/app-search/api/api_logs.rb +15 -16
- data/lib/elastic/app-search/api/count_analytics.rb +7 -5
- data/lib/elastic/app-search/api/create_curation.rb +8 -6
- data/lib/elastic/app-search/api/create_engine.rb +9 -7
- data/lib/elastic/app-search/api/create_synonym_set.rb +6 -5
- data/lib/elastic/app-search/api/curation.rb +6 -5
- data/lib/elastic/app-search/api/delete_curation.rb +6 -5
- data/lib/elastic/app-search/api/delete_documents.rb +7 -4
- data/lib/elastic/app-search/api/delete_engine.rb +5 -3
- data/lib/elastic/app-search/api/delete_meta_engine_source.rb +7 -4
- data/lib/elastic/app-search/api/delete_synonym_set.rb +6 -5
- data/lib/elastic/app-search/api/documents.rb +7 -4
- data/lib/elastic/app-search/api/engine.rb +5 -3
- data/lib/elastic/app-search/api/index_documents.rb +7 -4
- data/lib/elastic/app-search/api/list_curations.rb +7 -5
- data/lib/elastic/app-search/api/list_documents.rb +7 -5
- data/lib/elastic/app-search/api/list_engines.rb +7 -5
- data/lib/elastic/app-search/api/list_synonym_sets.rb +7 -5
- data/lib/elastic/app-search/api/log_clickthrough.rb +10 -7
- data/lib/elastic/app-search/api/multi_search.rb +8 -7
- data/lib/elastic/app-search/api/put_curation.rb +9 -8
- data/lib/elastic/app-search/api/put_documents.rb +7 -4
- data/lib/elastic/app-search/api/put_schema.rb +7 -4
- data/lib/elastic/app-search/api/put_search_settings.rb +6 -3
- data/lib/elastic/app-search/api/put_synonym_set.rb +7 -7
- data/lib/elastic/app-search/api/query_suggestion.rb +8 -6
- data/lib/elastic/app-search/api/reset_search_settings.rb +5 -3
- data/lib/elastic/app-search/api/schema.rb +6 -4
- data/lib/elastic/app-search/api/search.rb +5 -3
- data/lib/elastic/app-search/api/search_settings.rb +6 -4
- data/lib/elastic/app-search/api/synonym_set.rb +6 -5
- data/lib/elastic/app-search/api/top_clicks_analytics.rb +9 -7
- data/lib/elastic/app-search/api/top_queries_analytics.rb +8 -6
- data/lib/elastic/app-search/app_search.rb +19 -2
- data/lib/elastic/enterprise-search/api/health.rb +6 -1
- data/lib/elastic/enterprise-search/api/put_read_only.rb +5 -1
- data/lib/elastic/enterprise-search/api/read_only.rb +6 -1
- data/lib/elastic/enterprise-search/api/stats.rb +6 -2
- data/lib/elastic/enterprise-search/api/version.rb +6 -1
- data/lib/elastic/enterprise-search/client.rb +15 -2
- data/lib/elastic/enterprise-search/request.rb +25 -13
- data/lib/elastic/enterprise-search/utils.rb +5 -6
- data/lib/elastic/enterprise-search/version.rb +1 -1
- data/lib/elastic/enterprise_search.rb +1 -1
- data/lib/elastic/workplace-search/api/add_user_permissions.rb +10 -9
- data/lib/elastic/workplace-search/api/create_analytics_event.rb +59 -0
- data/lib/elastic/workplace-search/api/create_external_identity.rb +9 -7
- data/lib/elastic/workplace-search/api/delete_documents.rb +9 -7
- data/lib/elastic/workplace-search/api/delete_external_identity.rb +10 -6
- data/lib/elastic/workplace-search/api/external_identity.rb +10 -6
- data/lib/elastic/workplace-search/api/index_documents.rb +11 -8
- data/lib/elastic/workplace-search/api/list_external_identities.rb +11 -7
- data/lib/elastic/workplace-search/api/list_permissions.rb +11 -7
- data/lib/elastic/workplace-search/api/put_external_identity.rb +10 -9
- data/lib/elastic/workplace-search/api/put_user_permissions.rb +10 -9
- data/lib/elastic/workplace-search/api/remove_user_permissions.rb +10 -9
- data/lib/elastic/workplace-search/api/search.rb +19 -1
- data/lib/elastic/workplace-search/api/user_permissions.rb +10 -6
- data/lib/elastic/workplace-search/workplace_search.rb +26 -1
- data/spec/app-search/api_curations_spec.rb +97 -0
- data/spec/app-search/api_documents_spec.rb +20 -6
- data/spec/app-search/api_engines_spec.rb +4 -4
- data/{lib/generator/templates/_license.erb → spec/app-search/api_log_clickthrough_spec.rb} +18 -0
- data/spec/app-search/api_meta_engines_spec.rb +72 -0
- data/spec/app-search/api_query_suggestion_spec.rb +39 -0
- data/spec/app-search/api_schema_spec.rb +17 -3
- data/spec/app-search/api_search_settings_spec.rb +76 -0
- data/spec/app-search/api_synonyms_spec.rb +79 -0
- data/spec/app-search/client_spec.rb +20 -0
- data/spec/enterprise-search/client_spec.rb +11 -0
- data/spec/enterprise-search/request_spec.rb +22 -0
- data/spec/enterprise-search/utils_spec.rb +46 -0
- data/spec/fixtures/vcr/app_search/add_meta_engine_source.yml +109 -0
- data/spec/fixtures/vcr/app_search/api_documents.yml +56 -0
- data/spec/fixtures/vcr/app_search/{index_documents.yml → api_index_documents.yml} +11 -10
- data/spec/fixtures/vcr/app_search/api_log_clickthrough.yml +54 -0
- data/spec/fixtures/vcr/app_search/api_put_schema.yml +109 -0
- data/spec/fixtures/vcr/app_search/api_put_search_settings.yml +56 -0
- data/spec/fixtures/vcr/app_search/api_query_suggestion.yml +59 -0
- data/spec/fixtures/vcr/app_search/api_reset_search_settings.yml +56 -0
- data/spec/fixtures/vcr/app_search/{schema.yml → api_schema.yml} +12 -11
- data/spec/fixtures/vcr/app_search/api_search_settings.yml +56 -0
- data/spec/fixtures/vcr/app_search/create_curation.yml +113 -0
- data/spec/fixtures/vcr/{create_engine.yml → app_search/create_engine.yml} +0 -0
- data/spec/fixtures/vcr/app_search/create_meta_engine.yml +56 -0
- data/spec/fixtures/vcr/app_search/create_synonym_set.yml +56 -0
- data/spec/fixtures/vcr/app_search/delete_curation.yml +56 -0
- data/spec/fixtures/vcr/{delete_engine.yml → app_search/delete_engine.yml} +0 -0
- data/spec/fixtures/vcr/app_search/delete_meta_engine_source.yml +56 -0
- data/spec/fixtures/vcr/app_search/delete_synonym_set.yml +56 -0
- data/spec/fixtures/vcr/app_search/get_curation.yml +56 -0
- data/spec/fixtures/vcr/{get_engine.yml → app_search/get_engine.yml} +0 -0
- data/spec/fixtures/vcr/app_search/list_curations.yml +56 -0
- data/spec/fixtures/vcr/{list_engines.yml → app_search/list_engines.yml} +0 -0
- data/spec/fixtures/vcr/app_search/list_synonym_sets.yml +56 -0
- data/spec/fixtures/vcr/app_search/multi_query_search.yml +2 -2
- data/spec/fixtures/vcr/app_search/put_curation.yml +113 -0
- data/spec/fixtures/vcr/app_search/put_synonym_set.yml +56 -0
- data/spec/fixtures/vcr/app_search/synonym_set.yml +56 -0
- data/spec/fixtures/vcr/{add_user_permissions.yml → workplace_search/add_user_permissions.yml} +11 -9
- data/spec/fixtures/vcr/{clear_user_permissions.yml → workplace_search/clear_user_permissions.yml} +11 -9
- data/spec/fixtures/vcr/workplace_search/create_analytics_event.yml +55 -0
- data/spec/fixtures/vcr/workplace_search/create_external_identity.yml +53 -0
- data/spec/fixtures/vcr/{delete_documents.yml → workplace_search/delete_documents.yml} +11 -9
- data/spec/fixtures/vcr/workplace_search/delete_external_identity.yml +53 -0
- data/spec/fixtures/vcr/{index_documents.yml → workplace_search/index_documents.yml} +11 -9
- data/spec/fixtures/vcr/workplace_search/list_external_identities.yml +53 -0
- data/spec/fixtures/vcr/{list_permissions.yml → workplace_search/list_permissions.yml} +11 -9
- data/spec/fixtures/vcr/workplace_search/oauth_request_token.yml +57 -0
- data/spec/fixtures/vcr/workplace_search/put_external_identity.yml +53 -0
- data/spec/fixtures/vcr/{put_user_permissions.yml → workplace_search/put_user_permissions.yml} +22 -18
- data/spec/fixtures/vcr/{remove_user_permissions.yml → workplace_search/remove_user_permissions.yml} +11 -9
- data/spec/fixtures/vcr/workplace_search/retrieve_external_identity.yml +53 -0
- data/spec/fixtures/vcr/workplace_search/search_request.yml +60 -0
- data/spec/fixtures/vcr/{user_permissions_empty.yml → workplace_search/user_permissions_empty.yml} +11 -9
- data/spec/integration/enterprise_search_api_spec.rb +2 -2
- data/spec/spec_helper.rb +2 -0
- data/spec/workplace-search/client_spec.rb +10 -2
- data/spec/workplace-search/create_analytics_event_spec.rb +59 -0
- data/spec/workplace-search/documents_spec.rb +80 -0
- data/spec/workplace-search/external_identities_spec.rb +84 -0
- data/spec/workplace-search/{api_spec.rb → permissions_spec.rb} +14 -66
- data/spec/workplace-search/search_spec.rb +53 -0
- metadata +96 -36
- data/lib/generator/documentation_helper.rb +0 -94
- data/lib/generator/endpoint_generator.rb +0 -119
- data/lib/generator/parameters_exceptions.rb +0 -40
- data/lib/generator/parameters_helper.rb +0 -144
- data/lib/generator/templates/endpoint_template.erb +0 -29
- data/lib/generator/templates/spec_template.erb +0 -1
- data/lib/generator/utils.rb +0 -70
- data/spec/fixtures/vcr/create_document.yml +0 -54
@@ -0,0 +1,125 @@
|
|
1
|
+
[[connecting]]
|
2
|
+
== Connecting
|
3
|
+
|
4
|
+
|
5
|
+
This page contains the information you need to connect and use the Client with Elastic Enterprise Search.
|
6
|
+
|
7
|
+
**On this page**
|
8
|
+
|
9
|
+
* <<authentication>>
|
10
|
+
* <<custom_headers>>
|
11
|
+
|
12
|
+
|
13
|
+
[discrete]
|
14
|
+
[[authentication]]
|
15
|
+
=== Authentication
|
16
|
+
|
17
|
+
|
18
|
+
This section contains code snippets to show you how to connect to Enterprise Search, App Search, and Workplace Search.
|
19
|
+
|
20
|
+
Each service has its own authentication schemes. Using the `http_auth` property with either a string for a key / token or a tuple of `(username, password)` for basic authentication will set the proper `Authorization` HTTP header on the client instance.
|
21
|
+
|
22
|
+
[discrete]
|
23
|
+
[[auth-ent]]
|
24
|
+
==== Authenticating with Enterprise Search
|
25
|
+
|
26
|
+
Enterprise Search supports HTTP basic authentication with a username and password.
|
27
|
+
|
28
|
+
HTTP basic authentication uses the `http_auth` parameter by passing in a username and password as a tuple:
|
29
|
+
|
30
|
+
[source,rb]
|
31
|
+
----------------------------
|
32
|
+
http_auth = {user: 'elastic', password: 'password'}
|
33
|
+
host = 'https://id.ent-search.europe-west2.gcp.elastic-cloud.com'
|
34
|
+
|
35
|
+
ent_client = Elastic::EnterpriseSearch::Client.new(host: host, http_auth: http_auth)
|
36
|
+
----------------------------
|
37
|
+
|
38
|
+
|
39
|
+
[discrete]
|
40
|
+
[[auth-as]]
|
41
|
+
==== Authenticating with App Search
|
42
|
+
|
43
|
+
In your Elastic App Search dashboard, navigate to Credentials and Create a Key for the client to use. Make sure to read https://www.elastic.co/guide/en/app-search/current/authentication.html[the documentation on Authentication] 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.
|
44
|
+
|
45
|
+
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.
|
46
|
+
|
47
|
+
[source,rb]
|
48
|
+
----------------------------
|
49
|
+
host = 'https://id.ent-search.europe-west2.gcp.elastic-cloud.com'
|
50
|
+
api_key = 'private-api-key'
|
51
|
+
|
52
|
+
# From the Enterprise Search client:
|
53
|
+
ent_client = Elastic::EnterpriseSearch::Client.new(host: host)
|
54
|
+
ent_client.app_search.http_auth = api_key
|
55
|
+
|
56
|
+
# On its own
|
57
|
+
client = Elastic::EnterpriseSearch::AppSearch::Client.new(host: host, http_auth: api_key)
|
58
|
+
----------------------------
|
59
|
+
|
60
|
+
[discrete]
|
61
|
+
[[signed-search-key]]
|
62
|
+
===== Signed search key
|
63
|
+
|
64
|
+
App Search also supports https://www.elastic.co/guide/en/app-search/current/authentication.html#authentication-signed[authenticating with signed search keys]. Here's an example on how to use it:
|
65
|
+
|
66
|
+
[source,rb]
|
67
|
+
----------------------------
|
68
|
+
public_search_key = 'search-key-value'
|
69
|
+
# This name must match the name of the key above from your App Search dashboard
|
70
|
+
public_search_key_name = 'search-key'
|
71
|
+
|
72
|
+
# Say we have documents with a title and an author. We want this key to be able
|
73
|
+
# to search by title, but only return the author:
|
74
|
+
options = {
|
75
|
+
search_fields: { title: {} },
|
76
|
+
result_fields: { author: { raw: {} } }
|
77
|
+
}
|
78
|
+
|
79
|
+
signed_search_key = Elastic::EnterpriseSearch::AppSearch::Client.create_signed_search_key(public_search_key, public_search_key_name, options)
|
80
|
+
|
81
|
+
client = Elastic::EnterpriseSearch::AppSearch::Client.new(http_auth: signed_search_key)
|
82
|
+
|
83
|
+
client.search(engine_name, query: 'jungle')
|
84
|
+
----------------------------
|
85
|
+
|
86
|
+
[discrete]
|
87
|
+
[[auth-ws]]
|
88
|
+
==== Authenticating with Workplace Search
|
89
|
+
|
90
|
+
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 an `ID`. You'll need these in the following steps.
|
91
|
+
|
92
|
+
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:
|
93
|
+
|
94
|
+
[source,rb]
|
95
|
+
----------------------------
|
96
|
+
host = 'https://id.ent-search.europe-west2.gcp.elastic-cloud.com'
|
97
|
+
access_token = '<access token>'
|
98
|
+
content_source_id = '<content source id>'
|
99
|
+
|
100
|
+
# From the Enterprise Search client:
|
101
|
+
ent_client = Elastic::EnterpriseSearch::Client.new(host: host)
|
102
|
+
ent_client.workplace_search.http_auth = access_token
|
103
|
+
ent_client.workplace_search.index_documents(content_source_id, body: documents)
|
104
|
+
|
105
|
+
# On its own
|
106
|
+
workplace_search_client = Elastic::EnterpriseSearch::WorkplaceSearch::Client.new(
|
107
|
+
host: host,
|
108
|
+
http_auth: access_token
|
109
|
+
)
|
110
|
+
----------------------------
|
111
|
+
|
112
|
+
[discrete]
|
113
|
+
[[custom_headers]]
|
114
|
+
=== Custom HTTP Headers
|
115
|
+
|
116
|
+
You can pass in headers as a parameter to any of the API Endpoints to set custom headers for the request:
|
117
|
+
|
118
|
+
[source,rb]
|
119
|
+
----------------------------
|
120
|
+
headers = { 'x-custom-header' => 'Header value' }
|
121
|
+
workplace_search_client.index_documents(
|
122
|
+
content_source_id,
|
123
|
+
{ body: documents, headers: headers }
|
124
|
+
)
|
125
|
+
----------------------------
|
@@ -0,0 +1,42 @@
|
|
1
|
+
[[development]]
|
2
|
+
== Development
|
3
|
+
|
4
|
+
[discrete]
|
5
|
+
=== Run Stack locally
|
6
|
+
|
7
|
+
A rake task is included to run the Elastic Enterprise Search stack locally via Docker:
|
8
|
+
|
9
|
+
[source,bash]
|
10
|
+
----------------------------
|
11
|
+
$ rake stack[7.10.0]
|
12
|
+
----------------------------
|
13
|
+
|
14
|
+
This will run Elastic Enterprise Search in http://localhost:3002
|
15
|
+
- Username: `enterprise_search`
|
16
|
+
- Password: `changeme`
|
17
|
+
|
18
|
+
[discrete]
|
19
|
+
=== Run Tests
|
20
|
+
|
21
|
+
Unit tests for the clients:
|
22
|
+
|
23
|
+
[source,bash]
|
24
|
+
----------------------------
|
25
|
+
$ rake spec:client
|
26
|
+
----------------------------
|
27
|
+
|
28
|
+
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:
|
29
|
+
|
30
|
+
[source,bash]
|
31
|
+
----------------------------
|
32
|
+
$ ELASTIC_ENTERPRISE_HOST='http://localhost:3002' \
|
33
|
+
ELASTIC_ENTERPRISE_USER='elastic' \
|
34
|
+
ELASTIC_ENTERPRISE_PASSWORD='changeme' \
|
35
|
+
rake spec:integration
|
36
|
+
----------------------------
|
37
|
+
|
38
|
+
Run integration tests completely within containers, the way we run them on our CI:
|
39
|
+
[source,bash]
|
40
|
+
----------------------------
|
41
|
+
RUNSCRIPTS=enterprise-search STACK_VERSION=7.10.0 ./.ci/run-tests
|
42
|
+
----------------------------
|
@@ -0,0 +1,46 @@
|
|
1
|
+
[[enterprise-search-api]]
|
2
|
+
== Enterprise Search API
|
3
|
+
|
4
|
+
=== Health API
|
5
|
+
|
6
|
+
[source,rb]
|
7
|
+
----------------------------
|
8
|
+
> response = ent_client.health
|
9
|
+
> response.body
|
10
|
+
=> {"name"=>"...",
|
11
|
+
"version"=>{"number"=>"7.10.0", "build_hash"=>"...", "build_date"=>"..."},
|
12
|
+
"jvm"=>{...},
|
13
|
+
"filebeat"=>{...},
|
14
|
+
"system"=>{...}
|
15
|
+
}
|
16
|
+
----------------------------
|
17
|
+
|
18
|
+
=== Version API
|
19
|
+
|
20
|
+
[source,rb]
|
21
|
+
----------------------------
|
22
|
+
> response = ent_client.version
|
23
|
+
> response.body
|
24
|
+
=> {"number"=>"7.10.0", "build_hash"=>"...", "build_date"=>"..."}
|
25
|
+
----------------------------
|
26
|
+
|
27
|
+
=== Managing Read-Only mode:
|
28
|
+
|
29
|
+
[source,rb]
|
30
|
+
----------------------------
|
31
|
+
# Set read-only flag state
|
32
|
+
ent_client.put_read_only(body: { enabled: false })
|
33
|
+
|
34
|
+
# Get read-only flag state
|
35
|
+
ent_client.read_only
|
36
|
+
----------------------------
|
37
|
+
|
38
|
+
=== Stats API
|
39
|
+
|
40
|
+
[source,rb]
|
41
|
+
----------------------------
|
42
|
+
> ent_client.stats.body
|
43
|
+
=> {"app"=>{"pid"=>1, "start"=>"...", "end"=>"", "metrics"=>{...}},
|
44
|
+
"queues"=>{"connectors"=>{...}, "document_destroyer"=>{...}, "engine_destroyer"=>{...}, "index_adder"=>{...}, ...},
|
45
|
+
"connectors"=>{"alive"=>true, "pool"=>{...}, "job_store"=>{...}}}}
|
46
|
+
----------------------------
|
@@ -0,0 +1,17 @@
|
|
1
|
+
= enterprise-search-ruby
|
2
|
+
|
3
|
+
:doctype: book
|
4
|
+
|
5
|
+
include::{asciidoc-dir}/../../shared/attributes.asciidoc[]
|
6
|
+
|
7
|
+
include::overview.asciidoc[]
|
8
|
+
|
9
|
+
include::installation.asciidoc[]
|
10
|
+
|
11
|
+
include::connecting.asciidoc[]
|
12
|
+
|
13
|
+
include::enterprise-search-api.asciidoc[]
|
14
|
+
|
15
|
+
include::app-search-api.asciidoc[]
|
16
|
+
|
17
|
+
include::workplace-search-api.asciidoc[]
|
@@ -0,0 +1,18 @@
|
|
1
|
+
[[installation]]
|
2
|
+
== Installation
|
3
|
+
|
4
|
+
You can install Enterprise Search Client from Rubygems:
|
5
|
+
|
6
|
+
[source,sh]
|
7
|
+
---------------------------------------------------
|
8
|
+
$ gem install elastic-enterprise-search --pre
|
9
|
+
---------------------------------------------------
|
10
|
+
|
11
|
+
Or add it to your project's Gemfile:
|
12
|
+
|
13
|
+
[source,sh]
|
14
|
+
---------------------------------------------------
|
15
|
+
gem 'elastic-enterprise-search'
|
16
|
+
---------------------------------------------------
|
17
|
+
|
18
|
+
The version follows the Elastic Stack version so 7.10.0 is compatible with Enterprise Search released in Elastic Stack 7.10.0.
|
@@ -0,0 +1,59 @@
|
|
1
|
+
[[overview]]
|
2
|
+
== Overview
|
3
|
+
|
4
|
+
This is the official Ruby client for Elastic Enterprise Search.
|
5
|
+
|
6
|
+
[discrete]
|
7
|
+
=== Compatibility
|
8
|
+
|
9
|
+
Current development happens in the master branch.
|
10
|
+
|
11
|
+
The library is compatible with all Elastic Enterprise Search versions since `7.x` but you **have to use a matching major version**:
|
12
|
+
|
13
|
+
For **Elastic Enterprise Search 7.0** and later, use the major version 7 (`7.x.y`) of the library.
|
14
|
+
|
15
|
+
[discrete]
|
16
|
+
=== HTTP Library
|
17
|
+
This library uses https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-transport[elasticsearch-transport], the low-level Ruby client for connecting to an Elasticsearch cluster - also used in the official https://github.com/elastic/elasticsearch-ruby[Elasticsearch Ruby Client].
|
18
|
+
|
19
|
+
All requests, if successful, will return an `Elasticsearch::Transport::Transport::Response` instance. You can access the response `body`, `headers` and `status`.
|
20
|
+
|
21
|
+
`elasticsearch-transport` defines a https://github.com/elasticsearch/elasticsearch-ruby/blob/master/elasticsearch-transport/lib/elasticsearch/transport/transport/errors.rb[number of exception classes] for various client and server errors, as well as unsuccessful HTTP responses, making it possible to rescue specific exceptions with desired granularity. More details https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-transport#exception-handling[here]. You can find the full documentation for `elasticsearch-transport` at https://rubydoc.info/gems/elasticsearch-transport[RubyDoc].
|
22
|
+
|
23
|
+
The clients pass different options to transport, you can check them out https://rubydoc.info/github/elastic/enterprise-search-ruby/Elastic/EnterpriseSearch/Client[on RubyDocs].
|
24
|
+
|
25
|
+
[discrete]
|
26
|
+
==== Setting the host and port
|
27
|
+
|
28
|
+
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.
|
29
|
+
|
30
|
+
[discrete]
|
31
|
+
=== Logging
|
32
|
+
|
33
|
+
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:
|
34
|
+
|
35
|
+
[source,rb]
|
36
|
+
----------------------------
|
37
|
+
logger = MyLogger.new
|
38
|
+
client = Elastic::EnterpriseSearch::Client.new(logger: logger)
|
39
|
+
----------------------------
|
40
|
+
|
41
|
+
[discrete]
|
42
|
+
=== License
|
43
|
+
|
44
|
+
Licensed to Elasticsearch B.V. under one or more contributor
|
45
|
+
license agreements. See the NOTICE file distributed with
|
46
|
+
this work for additional information regarding copyright
|
47
|
+
ownership. Elasticsearch B.V. licenses this file to you under
|
48
|
+
the Apache License, Version 2.0 (the "License"); you may
|
49
|
+
not use this file except in compliance with the License.
|
50
|
+
You may obtain a copy of the License at
|
51
|
+
|
52
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
53
|
+
|
54
|
+
Unless required by applicable law or agreed to in writing,
|
55
|
+
software distributed under the License is distributed on an
|
56
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
57
|
+
KIND, either express or implied. See the License for the
|
58
|
+
specific language governing permissions and limitations
|
59
|
+
under the License.
|
@@ -0,0 +1,121 @@
|
|
1
|
+
[[workplace-search-api]]
|
2
|
+
== Workplace Search API
|
3
|
+
|
4
|
+
=== Documents
|
5
|
+
|
6
|
+
[source,rb]
|
7
|
+
----------------------------
|
8
|
+
# Index Documents
|
9
|
+
documents = [
|
10
|
+
{ id: 'e68fbc2688f1', title: 'Frankenstein; Or, The Modern Prometheus', author: 'Mary Wollstonecraft Shelley' },
|
11
|
+
{ id: '0682bb06af1a', title: 'Jungle Tales', author: 'Horacio Quiroga' },
|
12
|
+
{ id: '75015d85370d', title: 'Lenguas de diamante', author: 'Juana de Ibarbourou' },
|
13
|
+
{ id: 'c535e226aee3', title: 'Metamorphosis', author: 'Franz Kafka' }
|
14
|
+
]
|
15
|
+
|
16
|
+
response = client.index_documents(content_source_id, body: documents)
|
17
|
+
|
18
|
+
# Delete Documents
|
19
|
+
response = client.delete_documents(content_source_id, body: ['e68fbc2688f1', 'c535e226aee3'])
|
20
|
+
----------------------------
|
21
|
+
|
22
|
+
=== OAuth Authentication
|
23
|
+
|
24
|
+
You need to configure the OAuth Application for Search in order to use the Workplace Search client's `search` and `create_analytics` endpoints. You need to follow the steps in https://www.elastic.co/guide/en/workplace-search/current/building-custom-search-workplace-search.html#configuring-search-oauth[Configuring the OAuth Application for Search] to retrieve the credentials: Client ID and Client Secret to request access tokens from the authentication server.
|
25
|
+
|
26
|
+
[source,rb]
|
27
|
+
----------------------------
|
28
|
+
client = Elastic::EnterpriseSearch::WorkplaceSearch::Client.new(http_auth: <access_token>)
|
29
|
+
|
30
|
+
client_id = <client_id>
|
31
|
+
client_secret = <client_secret>
|
32
|
+
redirect_uri = <redirect_uri>
|
33
|
+
|
34
|
+
# Get the authorization URL:
|
35
|
+
client.authorization_url(client_id, redirect_uri)
|
36
|
+
> https://host:port/ws/oauth/authorize?response_type=code&client_id=client_id&redirect_uri=https%3A%2F%2Flocalhost%3A3002
|
37
|
+
----------------------------
|
38
|
+
|
39
|
+
Open the URL to authorize your application. Successful authorization redirects the user in accordance to the redirect URI provided (and configured for the application). The application server must now request for an access_token, which is generated by Workplace Search using the oauth/token endpoint, using the Client ID and Client Secret.
|
40
|
+
|
41
|
+
[source,rb]
|
42
|
+
----------------------------
|
43
|
+
authorization_code = '<paste code from redirect>'
|
44
|
+
|
45
|
+
access_token = client.request_access_token(client_id, client_secret, authorization_code, redirect_uri)
|
46
|
+
|
47
|
+
# The access_token can now be used to issue a search request:
|
48
|
+
client.search(body: {query: 'search query'}, access_token: access_token)
|
49
|
+
----------------------------
|
50
|
+
|
51
|
+
See https://www.elastic.co/guide/en/workplace-search/current/workplace-search-search-api.html#search-api-overview[Search API Overview] for more search parameters.
|
52
|
+
|
53
|
+
=== Permissions
|
54
|
+
|
55
|
+
[source,rb]
|
56
|
+
----------------------------
|
57
|
+
# List permissions
|
58
|
+
client.list_permissions(content_source_id)
|
59
|
+
|
60
|
+
# Get a user permissions
|
61
|
+
response = client.user_permissions(content_source_id, { user: 'enterprise_search' })
|
62
|
+
|
63
|
+
# Clear user permissions
|
64
|
+
client.put_user_permissions(content_source_id, { permissions: [], user: 'enterpise_search' })
|
65
|
+
|
66
|
+
# Add permissions to a user
|
67
|
+
client.add_user_permissions(
|
68
|
+
content_source_id,
|
69
|
+
{ permissions: ['permission1', 'permission2'], user: user }
|
70
|
+
)
|
71
|
+
|
72
|
+
# Updates user permissions
|
73
|
+
client.put_user_permissions(content_source_id, { permissions: [], user: user })
|
74
|
+
|
75
|
+
# Remove permissions from a user
|
76
|
+
client.remove_user_permissions(
|
77
|
+
content_source_id,
|
78
|
+
{ permissions: ['permission1', 'permission2'], user: user }
|
79
|
+
)
|
80
|
+
----------------------------
|
81
|
+
|
82
|
+
=== External Identities
|
83
|
+
|
84
|
+
[source,rb]
|
85
|
+
----------------------------
|
86
|
+
# Create external identities
|
87
|
+
body = { user: 'elastic_user', source_user_id: 'example@elastic.co' }
|
88
|
+
client.create_external_identity(content_source_id, body: body)
|
89
|
+
|
90
|
+
# Retrieve an external identity
|
91
|
+
client.external_identity(content_source_id, user: 'elastic_user')
|
92
|
+
|
93
|
+
# List external identities
|
94
|
+
client.list_external_identities(content_source_id)
|
95
|
+
|
96
|
+
# Update external identity
|
97
|
+
body = { source_user_id: 'example2@elastic.co' }
|
98
|
+
client.put_external_identity(content_source_id, user: 'elastic_user', body: body)
|
99
|
+
|
100
|
+
# Delete an external identity
|
101
|
+
client.delete_external_identity(content_source_id, user: 'elastic_user')
|
102
|
+
----------------------------
|
103
|
+
|
104
|
+
=== Create Analytics Event
|
105
|
+
|
106
|
+
You need to set up OAuth Authentication for analytics events.
|
107
|
+
|
108
|
+
[source,rb]
|
109
|
+
----------------------------
|
110
|
+
body = {
|
111
|
+
type: 'click',
|
112
|
+
query_id: 'search_query_id',
|
113
|
+
document_id: 'document_id',
|
114
|
+
page: 1,
|
115
|
+
content_source_id: 'content_source_id',
|
116
|
+
rank: 1,
|
117
|
+
event: 'api'
|
118
|
+
}
|
119
|
+
|
120
|
+
client.create_analytics_event(access_token: oauth_access_token, body: body)
|
121
|
+
----------------------------
|
@@ -28,15 +28,15 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.authors = ['Fernando Briano']
|
29
29
|
s.email = ['support@elastic.co']
|
30
30
|
s.homepage = 'https://github.com/elastic/enterprise-search-ruby'
|
31
|
-
s.summary = 'Official
|
31
|
+
s.summary = 'Official API client for Elastic Enterprise Search'
|
32
32
|
s.description = <<~DESCRIPTION
|
33
|
-
API client for
|
33
|
+
Official API client for Elastic Enterprise Search APIs.
|
34
34
|
DESCRIPTION
|
35
35
|
s.licenses = ['Apache-2.0']
|
36
36
|
|
37
37
|
s.metadata = {
|
38
38
|
'bug_tracker_uri' => 'https://github.com/elastic/enterprise-search-ruby/issues',
|
39
|
-
'documentation_uri' => 'https://
|
39
|
+
'documentation_uri' => 'https://www.elastic.co/guide/en/enterprise-search-clients/ruby/current/index.html',
|
40
40
|
'homepage_uri' => 'https://www.elastic.co/enterprise-search',
|
41
41
|
'source_code_uri' => 'https://github.com/elastic/enterprise-search-ruby'
|
42
42
|
}
|
@@ -46,7 +46,8 @@ Gem::Specification.new do |s|
|
|
46
46
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
47
47
|
s.require_paths = ['lib']
|
48
48
|
|
49
|
-
s.add_dependency 'elasticsearch-transport'
|
49
|
+
s.add_dependency 'elasticsearch-transport', '~> 7.11'
|
50
|
+
s.add_runtime_dependency 'jwt', '>= 1.5', '< 3.0'
|
50
51
|
s.add_development_dependency 'awesome_print'
|
51
52
|
s.add_development_dependency 'byebug' unless defined?(JRUBY_VERSION)
|
52
53
|
s.add_development_dependency 'rspec', '~> 3.9.0'
|