elastic-app-search 7.4.0 → 7.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +287 -20
- data/lib/elastic/app-search/client.rb +16 -2
- data/lib/elastic/app-search/client/analytics.rb +25 -0
- data/lib/elastic/app-search/client/click.rb +15 -0
- data/lib/elastic/app-search/client/credentials.rb +35 -0
- data/lib/elastic/app-search/client/curations.rb +35 -0
- data/lib/elastic/app-search/client/engines.rb +2 -0
- data/lib/elastic/app-search/client/logs.rb +15 -0
- data/lib/elastic/app-search/client/schema.rb +20 -0
- data/lib/elastic/app-search/client/synonyms.rb +35 -0
- data/lib/elastic/app-search/version.rb +1 -1
- data/spec/analytics_spec.rb +82 -0
- data/spec/click_spec.rb +30 -0
- data/spec/client_spec.rb +8 -452
- data/spec/config_helper.rb +4 -0
- data/spec/credentials_spec.rb +75 -0
- data/spec/curations_spec.rb +82 -0
- data/spec/documents_spec.rb +159 -0
- data/spec/engines_spec.rb +74 -0
- data/spec/logs_spec.rb +33 -0
- data/spec/query_suggestion_spec.rb +37 -0
- data/spec/schema_spec.rb +23 -0
- data/spec/search_settings_spec.rb +65 -0
- data/spec/search_spec.rb +96 -0
- data/spec/spec_helper.rb +69 -0
- data/spec/synonyms_spec.rb +65 -0
- metadata +33 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ad2aa4de4232586f616793b6f55332dde5d122fbe79ac5f80c62c42fa93bb07
|
4
|
+
data.tar.gz: 5413783fa304ac1c71b317f982a20d4d2d35b2eb6782721df285dd9ce58eadb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4896a9fb557f51ad81e44af96114d38463743781c777e93ff4b07d770b8cd941f48cb3cb5e7005a4282ea92d7859e8286bd1572152a10539bd50e63b07593b94
|
7
|
+
data.tar.gz: b235d0390fcb69242ad2dc23e400d042ea33278cdcb8038b06b4c9f32b8aec7cc9ccbd6117aaa06301f7858a88696c020aa8fc1710f2237da493f64de1768f33
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ To install the gem, execute:
|
|
25
25
|
gem install elastic-app-search
|
26
26
|
```
|
27
27
|
|
28
|
-
Or place `gem 'elastic-app-search', '~> 7.4.
|
28
|
+
Or place `gem 'elastic-app-search', '~> 7.4.1'` in your `Gemfile` and run `bundle install`.
|
29
29
|
|
30
30
|
## Versioning
|
31
31
|
|
@@ -192,7 +192,6 @@ client.search(engine_name, query, options)
|
|
192
192
|
|
193
193
|
```ruby
|
194
194
|
engine_name = 'favorite-videos'
|
195
|
-
|
196
195
|
queries = [{
|
197
196
|
:query => 'cat',
|
198
197
|
:options => { :search_fields => { :title => {} }}
|
@@ -208,7 +207,6 @@ client.multi_search(engine_name, queries)
|
|
208
207
|
|
209
208
|
```ruby
|
210
209
|
engine_name = 'favorite-videos'
|
211
|
-
|
212
210
|
options = {
|
213
211
|
:size => 3,
|
214
212
|
:types => {
|
@@ -233,30 +231,29 @@ client.show_settings(engine_name)
|
|
233
231
|
|
234
232
|
```ruby
|
235
233
|
engine_name = 'favorite-videos'
|
236
|
-
|
237
234
|
settings = {
|
238
|
-
|
239
|
-
|
240
|
-
|
235
|
+
'search_fields' => {
|
236
|
+
'id' => {
|
237
|
+
'weight' => 1
|
241
238
|
},
|
242
|
-
|
243
|
-
|
239
|
+
'url' => {
|
240
|
+
'weight' => 1
|
244
241
|
},
|
245
|
-
|
246
|
-
|
242
|
+
'title' => {
|
243
|
+
'weight' => 1
|
247
244
|
},
|
248
|
-
|
249
|
-
|
245
|
+
'body' => {
|
246
|
+
'weight' => 1
|
250
247
|
},
|
251
248
|
},
|
252
|
-
|
253
|
-
|
249
|
+
'boosts' => {
|
250
|
+
'title' => [
|
254
251
|
{
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
252
|
+
'type' => 'value',
|
253
|
+
'factor' => 9.5,
|
254
|
+
'operation' => 'multiply',
|
255
|
+
'value' => [
|
256
|
+
'Titanic'
|
260
257
|
]
|
261
258
|
}
|
262
259
|
]
|
@@ -292,10 +289,279 @@ client = Elastic::AppSearch::Client.new(host_identifier: 'host-c5s2mj', api_key:
|
|
292
289
|
client.search('national-parks-demo', 'everglade')
|
293
290
|
```
|
294
291
|
|
292
|
+
#### Log click-through
|
293
|
+
|
294
|
+
Logging a click through
|
295
|
+
|
296
|
+
```ruby
|
297
|
+
engine_name = 'favorite-videos'
|
298
|
+
options = {
|
299
|
+
:query => 'cat videos',
|
300
|
+
:document_id => 'INscMGmhmX4',
|
301
|
+
:request_id => 'e4c4dea0bd7ad3d2f676575ef16dc7d2',
|
302
|
+
:tags => ['firefox', 'web browser']
|
303
|
+
}
|
304
|
+
|
305
|
+
client.log_click_through(engine_name, options)
|
306
|
+
```
|
307
|
+
|
308
|
+
#### Analytics - Number of clicks-throughs received by a document
|
309
|
+
|
310
|
+
```ruby
|
311
|
+
engine_name = 'favorite-videos'
|
312
|
+
options = {
|
313
|
+
:query => 'cats',
|
314
|
+
:page => {
|
315
|
+
:size => 20,
|
316
|
+
},
|
317
|
+
:filters => {
|
318
|
+
:date => {
|
319
|
+
:from => '2019-04-11T00:00:00+00:00',
|
320
|
+
:to => '2019-04-13T00:00:00+00:00'
|
321
|
+
}
|
322
|
+
}
|
323
|
+
}
|
324
|
+
|
325
|
+
client.get_top_clicks_analytics(engine_name, options)
|
326
|
+
```
|
327
|
+
|
328
|
+
#### Analytics - Queries, number of queries, and clicks received
|
329
|
+
|
330
|
+
```ruby
|
331
|
+
engine_name = 'favorite-videos'
|
332
|
+
options = {
|
333
|
+
:page => {
|
334
|
+
:size => 20
|
335
|
+
},
|
336
|
+
:filters => {
|
337
|
+
:date => {
|
338
|
+
:from => '2019-04-11T00:00:00+00:00',
|
339
|
+
:to => '2019-04-13T00:00:00+00:00'
|
340
|
+
}
|
341
|
+
}
|
342
|
+
}
|
343
|
+
|
344
|
+
client.get_top_queries_analytics(engine_name, options)
|
345
|
+
```
|
346
|
+
|
347
|
+
#### Analytics - Number of clicks and total number of queries
|
348
|
+
|
349
|
+
```ruby
|
350
|
+
engine_name = 'favorite-videos'
|
351
|
+
options = {
|
352
|
+
:filters => {
|
353
|
+
:all => [
|
354
|
+
{
|
355
|
+
:tag => ['mobile', 'web']
|
356
|
+
},{
|
357
|
+
:query => 'cats'
|
358
|
+
}, {
|
359
|
+
:document_id => '163'
|
360
|
+
}, {
|
361
|
+
:date => {
|
362
|
+
:from => '2018-07-05T12:00:00+00:00',
|
363
|
+
:to => '2018-07-05T14:00:00+00:00'
|
364
|
+
}
|
365
|
+
}
|
366
|
+
]
|
367
|
+
},
|
368
|
+
:interval => 'hour'
|
369
|
+
}
|
370
|
+
|
371
|
+
client.get_count_analytics(engine_name, options)
|
372
|
+
```
|
373
|
+
|
374
|
+
#### Creating Synonym Sets
|
375
|
+
|
376
|
+
```ruby
|
377
|
+
engine_name = 'us-national-parks'
|
378
|
+
|
379
|
+
client.create_synonym_set(engine_name, :synonyms => ['park', 'trail'])
|
380
|
+
```
|
381
|
+
|
382
|
+
#### Retrieving Synonym Sets
|
383
|
+
|
384
|
+
```ruby
|
385
|
+
engine_name = 'us-national-parks'
|
386
|
+
|
387
|
+
client.get_synonym_set(engine_name, 'syn-5d8e6b5d40caae7dcb6e1b9c')
|
388
|
+
```
|
389
|
+
|
390
|
+
#### Listing Synonym Sets
|
391
|
+
|
392
|
+
```ruby
|
393
|
+
engine_name = 'us-national-parks'
|
394
|
+
|
395
|
+
client.list_synonym_sets(engine_name, :current => 1, :size => 20)
|
396
|
+
```
|
397
|
+
|
398
|
+
#### Updating Synonym Sets
|
399
|
+
|
400
|
+
```ruby
|
401
|
+
engine_name = 'us-national-parks'
|
402
|
+
|
403
|
+
client.update_synonym_set(engine_name, 'syn-5d8e6b5d40caae7dcb6e1b9c', :synonyms => ['park', 'trail', 'ground'])
|
404
|
+
```
|
405
|
+
|
406
|
+
#### Destroying Synonym Sets
|
407
|
+
|
408
|
+
```ruby
|
409
|
+
engine_name = 'us-national-parks'
|
410
|
+
|
411
|
+
client.destroy_synonym_set(engine_name, 'syn-5d8e6b5d40caae7dcb6e1b9c')
|
412
|
+
```
|
413
|
+
|
414
|
+
#### Listing Credentials
|
415
|
+
|
416
|
+
```ruby
|
417
|
+
client.list_credentials(:current => 1, :size => 20)
|
418
|
+
```
|
419
|
+
|
420
|
+
#### Retrieving Credentials
|
421
|
+
|
422
|
+
```ruby
|
423
|
+
client.get_credential('reading-private-key')
|
424
|
+
```
|
425
|
+
|
426
|
+
#### Creating Credentials
|
427
|
+
|
428
|
+
```ruby
|
429
|
+
client.create_credential({
|
430
|
+
:name => 'reading-private-key',
|
431
|
+
:type => 'private',
|
432
|
+
:read => true,
|
433
|
+
:write => false,
|
434
|
+
:access_all_engines => false,
|
435
|
+
:engines => [
|
436
|
+
'favorite-videos'
|
437
|
+
]
|
438
|
+
})
|
439
|
+
```
|
440
|
+
|
441
|
+
#### Updating Credentials
|
442
|
+
|
443
|
+
```ruby
|
444
|
+
client.update_credential('reading-private-key', {
|
445
|
+
:name => 'reading-private-key',
|
446
|
+
:type => 'private',
|
447
|
+
:read => true,
|
448
|
+
:write => true,
|
449
|
+
:access_all_engines => false,
|
450
|
+
:engines => [
|
451
|
+
'favorite-videos'
|
452
|
+
]
|
453
|
+
})
|
454
|
+
```
|
455
|
+
|
456
|
+
#### Destroying Credentials
|
457
|
+
|
458
|
+
```ruby
|
459
|
+
client.destroy_credential('reading-private-key')
|
460
|
+
```
|
461
|
+
|
462
|
+
#### Retrieving an Engine's Schema
|
463
|
+
|
464
|
+
```ruby
|
465
|
+
engine_name = 'us-national-parks'
|
466
|
+
|
467
|
+
client.get_schema(engine_name)
|
468
|
+
```
|
469
|
+
|
470
|
+
#### Updating an Engine's Schema or Creating a New Schema Field
|
471
|
+
|
472
|
+
```ruby
|
473
|
+
engine_name = 'us-national-parks'
|
474
|
+
|
475
|
+
client.update_schema(engine_name, 'square_km' => 'number')
|
476
|
+
```
|
477
|
+
|
478
|
+
#### Creating Curations
|
479
|
+
|
480
|
+
```ruby
|
481
|
+
engine_name = 'us-national-parks'
|
482
|
+
options = {
|
483
|
+
'queries' => [
|
484
|
+
'zion'
|
485
|
+
],
|
486
|
+
'promoted' => [
|
487
|
+
'doc-5d8e413b40caaedab76e3c96'
|
488
|
+
],
|
489
|
+
'hidden' => [
|
490
|
+
'doc-5d8e413d40caae335e06c374'
|
491
|
+
]
|
492
|
+
}
|
493
|
+
|
494
|
+
client.create_curation(engine_name, options)
|
495
|
+
```
|
496
|
+
|
497
|
+
#### Retrieving Curations
|
498
|
+
|
499
|
+
```ruby
|
500
|
+
engine_name = 'us-national-parks'
|
501
|
+
|
502
|
+
client.get_curation(engine_name, 'cur-5d9240d640caaeca6506b600')
|
503
|
+
```
|
504
|
+
|
505
|
+
#### Listing Curations
|
506
|
+
|
507
|
+
```ruby
|
508
|
+
engine_name = 'us-national-parks'
|
509
|
+
|
510
|
+
client.list_curations(engine_name, current: 1, size: 20)
|
511
|
+
```
|
512
|
+
|
513
|
+
#### Updating Curations
|
514
|
+
|
515
|
+
```ruby
|
516
|
+
engine_name = 'us-national-parks'
|
517
|
+
id = 'cur-5d9240d640caaeca6506b600'
|
518
|
+
options = {
|
519
|
+
'queries' => [
|
520
|
+
'zion'
|
521
|
+
],
|
522
|
+
'promoted' => [
|
523
|
+
'doc-5d8e413b40caaedab76e3c96'
|
524
|
+
]
|
525
|
+
}
|
526
|
+
|
527
|
+
client.update_curation(engine_name, id, options)
|
528
|
+
```
|
529
|
+
|
530
|
+
#### Destroying Curations
|
531
|
+
|
532
|
+
```ruby
|
533
|
+
engine_name = 'us-national-parks'
|
534
|
+
|
535
|
+
client.destroy_curation(engine_name, 'cur-5d9240d640caaeca6506b600')
|
536
|
+
```
|
537
|
+
|
538
|
+
#### Retrieving API Logs
|
539
|
+
|
540
|
+
```ruby
|
541
|
+
engine_name = 'us-national-parks'
|
542
|
+
options = {
|
543
|
+
'filters' => {
|
544
|
+
'date' => {
|
545
|
+
'from' => '2019-09-23T00:00:00+00:00',
|
546
|
+
'to' => '2019-09-28T00:00:00+00:00'
|
547
|
+
}
|
548
|
+
},
|
549
|
+
'page' => {
|
550
|
+
'total_results' => 100,
|
551
|
+
'size' => 20
|
552
|
+
},
|
553
|
+
'query' => 'search',
|
554
|
+
'sort_direction' => 'desc'
|
555
|
+
}
|
556
|
+
|
557
|
+
client.get_api_logs(engine_name, options)
|
558
|
+
```
|
559
|
+
|
295
560
|
## Running Tests
|
296
561
|
|
297
562
|
```bash
|
298
563
|
export AS_API_KEY="[API_KEY]"
|
564
|
+
export AS_ADMIN_KEY="[ADMIN_API_KEY]"
|
299
565
|
export AS_HOST_IDENTIFIER="[HOST_IDENTIFIER]"
|
300
566
|
bundle exec rspec
|
301
567
|
```
|
@@ -304,6 +570,7 @@ You can also run tests against a local environment by passing a `AS_API_ENDPOINT
|
|
304
570
|
|
305
571
|
```bash
|
306
572
|
export AS_API_KEY="[API_KEY]"
|
573
|
+
export AS_ADMIN_KEY="[ADMIN_API_KEY]"
|
307
574
|
export AS_API_ENDPOINT="http://[HOST_IDENTIFIER].api.127.0.0.1.ip.es.io:3002/api/as/v1"
|
308
575
|
bundle exec rspec
|
309
576
|
```
|
@@ -7,11 +7,18 @@ module Elastic
|
|
7
7
|
module AppSearch
|
8
8
|
# API client for the {Elastic App Search API}[https://www.elastic.co/cloud/app-search-service].
|
9
9
|
class Client
|
10
|
+
autoload :Analytics, 'elastic/app-search/client/analytics'
|
11
|
+
autoload :Click, 'elastic/app-search/client/click'
|
12
|
+
autoload :Credentials, 'elastic/app-search/client/credentials'
|
13
|
+
autoload :Curations, 'elastic/app-search/client/curations'
|
10
14
|
autoload :Documents, 'elastic/app-search/client/documents'
|
11
15
|
autoload :Engines, 'elastic/app-search/client/engines'
|
16
|
+
autoload :Logs, 'elastic/app-search/client/logs'
|
17
|
+
autoload :Schema, 'elastic/app-search/client/schema'
|
12
18
|
autoload :Search, 'elastic/app-search/client/search'
|
13
|
-
autoload :QuerySuggestion, 'elastic/app-search/client/query_suggestion'
|
14
19
|
autoload :SearchSettings, 'elastic/app-search/client/search_settings'
|
20
|
+
autoload :Synonyms, 'elastic/app-search/client/synonyms'
|
21
|
+
autoload :QuerySuggestion, 'elastic/app-search/client/query_suggestion'
|
15
22
|
|
16
23
|
DEFAULT_TIMEOUT = 15
|
17
24
|
|
@@ -56,12 +63,19 @@ module Elastic
|
|
56
63
|
end
|
57
64
|
end
|
58
65
|
|
66
|
+
include Elastic::AppSearch::Client::Analytics
|
67
|
+
include Elastic::AppSearch::Client::Click
|
68
|
+
include Elastic::AppSearch::Client::Credentials
|
69
|
+
include Elastic::AppSearch::Client::Curations
|
59
70
|
include Elastic::AppSearch::Client::Documents
|
60
71
|
include Elastic::AppSearch::Client::Engines
|
72
|
+
include Elastic::AppSearch::Client::Logs
|
73
|
+
include Elastic::AppSearch::Client::Schema
|
61
74
|
include Elastic::AppSearch::Client::Search
|
75
|
+
include Elastic::AppSearch::Client::SearchSettings
|
62
76
|
include Elastic::AppSearch::Client::SignedSearchOptions
|
77
|
+
include Elastic::AppSearch::Client::Synonyms
|
63
78
|
include Elastic::AppSearch::Client::QuerySuggestion
|
64
|
-
include Elastic::AppSearch::Client::SearchSettings
|
65
79
|
end
|
66
80
|
end
|
67
81
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Analytics API - https://swiftype.com/documentation/app-search/api/analytics
|
2
|
+
module Elastic
|
3
|
+
module AppSearch
|
4
|
+
class Client
|
5
|
+
module Analytics
|
6
|
+
|
7
|
+
# Returns the number of clicks received by a document in descending order.
|
8
|
+
def get_top_clicks_analytics(engine_name, options)
|
9
|
+
post("engines/#{engine_name}/analytics/clicks", options)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns queries analytics by usage count
|
13
|
+
def get_top_queries_analytics(engine_name, options)
|
14
|
+
post("engines/#{engine_name}/analytics/queries", options)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns the number of clicks and total number of queries over a period.
|
18
|
+
def get_count_analytics(engine_name, options)
|
19
|
+
post("engines/#{engine_name}/analytics/counts", options)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Click API - https://swiftype.com/documentation/app-search/api/clickthrough
|
2
|
+
module Elastic
|
3
|
+
module AppSearch
|
4
|
+
class Client
|
5
|
+
module Click
|
6
|
+
|
7
|
+
# Send data about clicked results.
|
8
|
+
def log_click_through(engine_name, options)
|
9
|
+
post("engines/#{engine_name}/documents", options)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|