search_flip 2.3.2 → 3.0.0.beta
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/.rubocop.yml +21 -21
- data/.travis.yml +3 -5
- data/CHANGELOG.md +21 -5
- data/Gemfile +0 -2
- data/README.md +36 -16
- data/Rakefile +0 -1
- data/UPDATING.md +91 -0
- data/lib/search_flip/aggregatable.rb +0 -2
- data/lib/search_flip/aggregation.rb +8 -17
- data/lib/search_flip/bulk.rb +1 -3
- data/lib/search_flip/config.rb +0 -2
- data/lib/search_flip/connection.rb +40 -13
- data/lib/search_flip/criteria.rb +38 -105
- data/lib/search_flip/exceptions.rb +0 -2
- data/lib/search_flip/filterable.rb +51 -38
- data/lib/search_flip/helper.rb +13 -0
- data/lib/search_flip/http_client.rb +1 -7
- data/lib/search_flip/index.rb +21 -4
- data/lib/search_flip/json.rb +0 -2
- data/lib/search_flip/model.rb +0 -2
- data/lib/search_flip/post_filterable.rb +31 -36
- data/lib/search_flip/response.rb +5 -7
- data/lib/search_flip/result.rb +0 -2
- data/lib/search_flip/to_json.rb +4 -6
- data/lib/search_flip/version.rb +1 -3
- data/lib/search_flip.rb +1 -3
- data/search_flip.gemspec +4 -5
- data/spec/delegate_matcher.rb +0 -2
- data/spec/search_flip/aggregation_spec.rb +3 -4
- data/spec/search_flip/bulk_spec.rb +24 -19
- data/spec/search_flip/connection_spec.rb +48 -7
- data/spec/search_flip/criteria_spec.rb +178 -24
- data/spec/search_flip/http_client_spec.rb +0 -1
- data/spec/search_flip/index_spec.rb +25 -13
- data/spec/search_flip/model_spec.rb +0 -1
- data/spec/search_flip/response_spec.rb +0 -4
- data/spec/search_flip/to_json_spec.rb +0 -1
- data/spec/spec_helper.rb +1 -3
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f16c0308f14d764aab7fa477c8ba4169bf7d493e774cd8f435d8fa0ecd9ce991
|
4
|
+
data.tar.gz: 7a91d1a23b846eb17466369d82ec5583b6346d237037cd12c0cd8e036df2498d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5ccd27acffd9cd2e91a66c3b4e99c9fb09d30d8c720785cedaf233ba314e28d2317c331fc7d63a29ef29d9951bd071d8ed849ffd0e3486e6890d428b3c94317
|
7
|
+
data.tar.gz: a7f5b2f4969d7daa6aa578f4a31588b263f44f7e48aa4729bc820032923b804254cb0ad941dc961b8f36c508f07b27ef2ac7198802b02db2385cd1487b32cdc8
|
data/.rubocop.yml
CHANGED
@@ -1,23 +1,35 @@
|
|
1
|
-
Style/
|
1
|
+
Style/HashTransformValues:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Style/HashTransformKeys:
|
2
5
|
Enabled: false
|
3
6
|
|
4
|
-
Style/
|
7
|
+
Style/HashEachMethods:
|
8
|
+
Enabled: true
|
9
|
+
|
10
|
+
Style/FrozenStringLiteralComment:
|
5
11
|
Enabled: false
|
6
12
|
|
7
|
-
|
13
|
+
Lint/RedundantRequireStatement:
|
8
14
|
Enabled: false
|
9
15
|
|
16
|
+
Layout/ArgumentAlignment:
|
17
|
+
EnforcedStyle: with_fixed_indentation
|
18
|
+
|
19
|
+
Layout/FirstArrayElementIndentation:
|
20
|
+
EnforcedStyle: consistent
|
21
|
+
|
10
22
|
Style/PercentLiteralDelimiters:
|
11
23
|
Enabled: false
|
12
24
|
|
13
25
|
Style/SpecialGlobalVars:
|
14
|
-
|
26
|
+
EnforcedStyle: use_english_names
|
15
27
|
|
16
28
|
Security/Eval:
|
17
29
|
Enabled: false
|
18
30
|
|
19
31
|
Style/WordArray:
|
20
|
-
|
32
|
+
EnforcedStyle: brackets
|
21
33
|
|
22
34
|
Style/ClassAndModuleChildren:
|
23
35
|
Enabled: false
|
@@ -34,19 +46,16 @@ Style/StringLiteralsInInterpolation:
|
|
34
46
|
Metrics/ClassLength:
|
35
47
|
Enabled: false
|
36
48
|
|
37
|
-
Naming/
|
49
|
+
Naming/MethodParameterName:
|
38
50
|
Enabled: false
|
39
51
|
|
40
52
|
Style/SymbolArray:
|
41
|
-
|
53
|
+
EnforcedStyle: brackets
|
42
54
|
|
43
55
|
Layout/RescueEnsureAlignment:
|
44
56
|
Enabled: false
|
45
57
|
|
46
|
-
Layout/
|
47
|
-
Enabled: false
|
48
|
-
|
49
|
-
Metrics/LineLength:
|
58
|
+
Layout/LineLength:
|
50
59
|
Enabled: false
|
51
60
|
|
52
61
|
Metrics/MethodLength:
|
@@ -58,9 +67,6 @@ Metrics/ModuleLength:
|
|
58
67
|
Style/ZeroLengthPredicate:
|
59
68
|
Enabled: false
|
60
69
|
|
61
|
-
Layout/TrailingBlankLines:
|
62
|
-
Enabled: false
|
63
|
-
|
64
70
|
Metrics/PerceivedComplexity:
|
65
71
|
Enabled: false
|
66
72
|
|
@@ -100,20 +106,14 @@ Style/MutableConstant:
|
|
100
106
|
Layout/MultilineMethodCallIndentation:
|
101
107
|
EnforcedStyle: indented
|
102
108
|
|
103
|
-
Layout/
|
109
|
+
Layout/ParameterAlignment:
|
104
110
|
EnforcedStyle: with_fixed_indentation
|
105
111
|
|
106
112
|
Lint/UnusedMethodArgument:
|
107
113
|
Enabled: false
|
108
114
|
|
109
|
-
Layout/IndentArray:
|
110
|
-
EnforcedStyle: consistent
|
111
|
-
|
112
115
|
Style/IfUnlessModifier:
|
113
116
|
Enabled: false
|
114
117
|
|
115
118
|
Style/RedundantBegin:
|
116
119
|
Enabled: false
|
117
|
-
|
118
|
-
Style/OptionalArguments:
|
119
|
-
Enabled: false
|
data/.travis.yml
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
|
2
1
|
sudo: false
|
3
2
|
language: ruby
|
4
3
|
env:
|
5
|
-
- ES_IMAGE=elasticsearch:1
|
6
4
|
- ES_IMAGE=plainpicture/elasticsearch:2.4.1_delete-by-query
|
7
5
|
- ES_IMAGE=elasticsearch:5.4
|
8
6
|
- ES_IMAGE=docker.elastic.co/elasticsearch/elasticsearch:6.7.0
|
@@ -10,11 +8,11 @@ env:
|
|
10
8
|
- ES_IMAGE=docker.elastic.co/elasticsearch/elasticsearch:7.4.0
|
11
9
|
rvm:
|
12
10
|
- ruby-2.6.2
|
13
|
-
- ruby-2.7.1
|
14
11
|
before_install:
|
15
12
|
- docker-compose up -d
|
16
13
|
- sleep 10
|
17
14
|
install:
|
18
15
|
- travis_retry bundle install
|
19
|
-
script:
|
20
|
-
|
16
|
+
script:
|
17
|
+
- bundle exec rspec
|
18
|
+
- bundle exec rubocop
|
data/CHANGELOG.md
CHANGED
@@ -1,24 +1,40 @@
|
|
1
1
|
|
2
2
|
# CHANGELOG
|
3
3
|
|
4
|
-
##
|
4
|
+
## v3.0.0
|
5
5
|
|
6
|
-
*
|
6
|
+
* Added `Criteria#to_query`, which returns a raw query including all queries
|
7
|
+
and filters, including the post filters
|
8
|
+
* Added `Criteria#all`
|
9
|
+
* [BREAKING] Support for elasticsearch 1.x has been removed
|
10
|
+
* [BREAKING] No longer pass multiple arguments to `#must`, `#must_not`,
|
11
|
+
`#filter`, `#should`, `#post_must`, `#post_must_not`, `#post_filter`, and
|
12
|
+
`#post_should`. Pass an array of arguments instead: `.post_must([...])`
|
13
|
+
* [BREAKING] `#should` and `#post_should` is now equivalent to
|
14
|
+
`.must(bool: { should: ... })` and `.post_must(bool: { should: ... })`,
|
15
|
+
* [BREAKING] `#unscope` is removed
|
16
|
+
* [BREAKING] `SearchFlip::Connection#get_aliases` no longer returns a
|
17
|
+
Hashie::Mash, but a raw Hash as was already stated in the docs
|
18
|
+
* `#post_where` and `#post_where_not` now handle `nil` values as well:
|
19
|
+
`.post_where_not(title: nil)` with `exists/exists not` filters
|
20
|
+
* `Connection#cat_indices/get_indices` now accepts additional parameters
|
21
|
+
* `Connection#freeze_index`, `Connection#unfreeze_index`, `Index#freeze_index`
|
22
|
+
and `Index#unfreeze_index` added
|
7
23
|
|
8
24
|
## v2.3.1
|
9
25
|
|
10
|
-
* Make search_flip work with hashie 4.0.0
|
26
|
+
* Make `search_flip` work with hashie 4.0.0
|
11
27
|
|
12
28
|
## v2.3.0
|
13
29
|
|
14
30
|
* [DEPRECATED] `SearchFlip::Criteria#should` is deprecated and will become
|
15
|
-
equivalent to `.must(bool: { should: ... })` in search_flip 3
|
31
|
+
equivalent to `.must(bool: { should: ... })` in `search_flip` 3
|
16
32
|
* Added `SearchFlip::Criteria#explain`
|
17
33
|
|
18
34
|
## v2.2.0
|
19
35
|
|
20
36
|
* [DEPRECATED] `SearchFlip::Criteria#unscope` is deprecated and will be removed
|
21
|
-
in search_flip 3
|
37
|
+
in `search_flip` 3
|
22
38
|
* Added `SearchFlip::Criteria#track_total_hits`
|
23
39
|
|
24
40
|
## v2.1.0
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
Using SearchFlip it is dead-simple to create index classes that correspond to
|
10
10
|
[Elasticsearch](https://www.elastic.co/) indices and to manipulate, query and
|
11
11
|
aggregate these indices using a chainable, concise, yet powerful DSL. Finally,
|
12
|
-
SearchFlip supports Elasticsearch
|
12
|
+
SearchFlip supports Elasticsearch 2.x, 5.x, 6.x, 7.x. Check section
|
13
13
|
[Feature Support](#feature-support) for version dependent features.
|
14
14
|
|
15
15
|
```ruby
|
@@ -245,7 +245,6 @@ CommentIndex.search("hello world").sort(id: "desc").aggregate(:username).request
|
|
245
245
|
# => {:query=>{:bool=>{:must=>[{:query_string=>{:query=>"hello world", :default_operator=>:AND}}]}}, ...}
|
246
246
|
```
|
247
247
|
|
248
|
-
|
249
248
|
Delete records:
|
250
249
|
|
251
250
|
```ruby
|
@@ -335,7 +334,7 @@ CommentIndex.where(state: ["approved", "rejected"])
|
|
335
334
|
|
336
335
|
* `where_not`
|
337
336
|
|
338
|
-
The `.where_not` method is like
|
337
|
+
The `.where_not` method is like `.where`, but excluding the matching documents:
|
339
338
|
|
340
339
|
```ruby
|
341
340
|
CommentIndex.where_not(id: [1, 2, 3])
|
@@ -362,7 +361,10 @@ CommentIndex.filter(term: { state: "approved" })
|
|
362
361
|
Use `.should` to add raw should queries:
|
363
362
|
|
364
363
|
```ruby
|
365
|
-
CommentIndex.should(
|
364
|
+
CommentIndex.should([
|
365
|
+
{ term: { state: "approved" } },
|
366
|
+
{ term: { user: "mrkamel" } },
|
367
|
+
])
|
366
368
|
```
|
367
369
|
|
368
370
|
* `must`
|
@@ -371,15 +373,6 @@ Use `.must` to add raw must queries:
|
|
371
373
|
|
372
374
|
```ruby
|
373
375
|
CommentIndex.must(term: { state: "approved" })
|
374
|
-
|
375
|
-
CommentIndex.must(
|
376
|
-
bool: {
|
377
|
-
should: [
|
378
|
-
{ terms: { state: ["approved", "rejected"] }},
|
379
|
-
{ term: { username: "mrkamel" }}
|
380
|
-
]
|
381
|
-
}
|
382
|
-
)
|
383
376
|
```
|
384
377
|
|
385
378
|
* `must_not`
|
@@ -426,6 +419,35 @@ Simply matches all documents:
|
|
426
419
|
CommentIndex.match_all
|
427
420
|
```
|
428
421
|
|
422
|
+
* `all`
|
423
|
+
|
424
|
+
Simply returns the criteria as is or an empty criteria when called on the index
|
425
|
+
class directly. Useful for chaining.
|
426
|
+
|
427
|
+
```ruby
|
428
|
+
CommentIndex.all
|
429
|
+
```
|
430
|
+
|
431
|
+
* `to_query`
|
432
|
+
|
433
|
+
Sometimes, you want to convert the constraints of a search flip query to a raw
|
434
|
+
query to e.g. use it in a should clause:
|
435
|
+
|
436
|
+
```ruby
|
437
|
+
CommentIndex.should([
|
438
|
+
CommentIndex.range(:likes_count, gt: 10).to_query,
|
439
|
+
CommentIndex.search("search term").to_query
|
440
|
+
])
|
441
|
+
```
|
442
|
+
|
443
|
+
It returns all added queries and filters, including post filters as a raw
|
444
|
+
query:
|
445
|
+
|
446
|
+
```ruby
|
447
|
+
CommentIndex.where(state: "new").search("text").to_query
|
448
|
+
# => {:bool=>{:filter=>[{:term=>{:state=>"new"}}], :must=>[{:query_string=>{:query=>"text", ...}}]}}
|
449
|
+
```
|
450
|
+
|
429
451
|
### Post Query/Filter Criteria Methods
|
430
452
|
|
431
453
|
All query/filter criteria methods (`#where`, `#where_not`, `#range`, etc.) are available
|
@@ -835,15 +857,13 @@ require "search_flip/to_json"
|
|
835
857
|
|
836
858
|
## Feature Support
|
837
859
|
|
838
|
-
* `#post_search` and `#profile` are only supported from up to Elasticsearch
|
839
|
-
version >= 2.
|
840
860
|
* for Elasticsearch 2.x, the delete-by-query plugin is required to delete
|
841
861
|
records via queries
|
842
862
|
* `#track_total_hits` is only available with Elasticsearch >= 7
|
843
863
|
|
844
864
|
## Keeping your Models and Indices in Sync
|
845
865
|
|
846
|
-
Besides the most basic approach to get you started,
|
866
|
+
Besides the most basic approach to get you started, SearchFlip currently doesn't
|
847
867
|
ship with any means to automatically keep your models and indices in sync,
|
848
868
|
because every method is very much bound to the concrete environment and depends
|
849
869
|
on your concrete requirements. In addition, the methods to achieve model/index
|
data/Rakefile
CHANGED
data/UPDATING.md
CHANGED
@@ -1,6 +1,97 @@
|
|
1
1
|
|
2
2
|
# Updating from previous SearchFlip versions
|
3
3
|
|
4
|
+
## Update 2.x to 3.x
|
5
|
+
|
6
|
+
* **[BREAKING]** No longer pass multiple arguments to `#must`, `#must_not`,
|
7
|
+
`#filter`, `#should`, `#post_must`, `#post_must_not`, `#post_filter`, and
|
8
|
+
`#post_should`.
|
9
|
+
|
10
|
+
2.x:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
CommentIndex.must({ term: { state: "new" } }, { term: { state: "approved" } })
|
14
|
+
```
|
15
|
+
|
16
|
+
3.x:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
CommentIndex.must([
|
20
|
+
{ term: { state: "new" } },
|
21
|
+
{ term: { state: "approved" } }
|
22
|
+
])
|
23
|
+
```
|
24
|
+
|
25
|
+
Same for `#must_not`, `#filter`, `#should`, etc.
|
26
|
+
|
27
|
+
* **[BREAKING]** `#should` and `#post_should` is now equivalent to `.must(bool: {
|
28
|
+
should: ... })` and `.post_must(bool: { should: ... })`, respectively.
|
29
|
+
|
30
|
+
No necessary code changes, but different queries will be produced:
|
31
|
+
|
32
|
+
2.x:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
query = CommentIndex.should([
|
36
|
+
{ term: { state: "new" } },
|
37
|
+
{ term: { state: "approved" }}
|
38
|
+
])
|
39
|
+
|
40
|
+
query = query.should([
|
41
|
+
{ term: { state: "declined" } },
|
42
|
+
{ term: { state: "pending" } }
|
43
|
+
])
|
44
|
+
```
|
45
|
+
|
46
|
+
generated a query matching:
|
47
|
+
|
48
|
+
`new OR approved OR declined OR pending`
|
49
|
+
|
50
|
+
3.x:
|
51
|
+
|
52
|
+
SearchFlip 3 generates a query matching:
|
53
|
+
|
54
|
+
`(new OR approved) AND (declined OR pending)`
|
55
|
+
|
56
|
+
as desired in nearly all cases.
|
57
|
+
|
58
|
+
* [BREAKING] `#unscope` is removed
|
59
|
+
|
60
|
+
There is no equivalent replacement, but you can achieve the same by using the
|
61
|
+
intermediate queries instead:
|
62
|
+
|
63
|
+
2.x:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
query1 = CommentIndex.where(price: 0..20).search("some terms")
|
67
|
+
query2 = query1.unscope(:search)
|
68
|
+
```
|
69
|
+
|
70
|
+
3.x
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
query1 = CommentIndex.where(price: 0..20)
|
74
|
+
query2 = query1.search("some terms")
|
75
|
+
```
|
76
|
+
|
77
|
+
* **[BREAKING]** `SearchFlip::Connection#get_aliases` no longer returns a
|
78
|
+
Hashie::Mash, but a raw Hash as was already stated in the docs
|
79
|
+
|
80
|
+
Code changes are only neccessary if you use methods related to `Hashie::Mash`
|
81
|
+
on the result of `#get_aliases` like e.g.
|
82
|
+
|
83
|
+
2.x:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
CommentIndex.connection.get_aliases['index_name'].aliases
|
87
|
+
```
|
88
|
+
|
89
|
+
3.x:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
CommentIndex.connection.get_aliases['index_name']['aliases']
|
93
|
+
```
|
94
|
+
|
4
95
|
## Update 1.x to 2.x
|
5
96
|
|
6
97
|
* **[BREAKING]** No longer include the `type_name` in `SearchFlip::Index.mapping`
|
@@ -1,12 +1,11 @@
|
|
1
|
-
|
2
1
|
module SearchFlip
|
3
2
|
# The SearchFlip::Aggregation class puts together everything
|
4
3
|
# required to use the Elasticsearch aggregation framework via mixins and
|
5
4
|
# adds a method to convert it to a hash format to be used in the request.
|
6
5
|
|
7
6
|
class Aggregation
|
8
|
-
include
|
9
|
-
include
|
7
|
+
include Filterable
|
8
|
+
include Aggregatable
|
10
9
|
|
11
10
|
attr_reader :target
|
12
11
|
|
@@ -24,22 +23,17 @@ module SearchFlip
|
|
24
23
|
res = {}
|
25
24
|
res[:aggregations] = aggregation_values if aggregation_values
|
26
25
|
|
27
|
-
if must_values ||
|
26
|
+
if must_values || must_not_values || filter_values
|
28
27
|
if target.connection.version.to_i >= 2
|
29
28
|
res[:filter] = {
|
30
29
|
bool: {}
|
31
|
-
.merge(must_values
|
30
|
+
.merge(must_values ? { must: must_values } : {})
|
32
31
|
.merge(must_not_values ? { must_not: must_not_values } : {})
|
33
|
-
.merge(should_values ? { should: should_values } : {})
|
34
32
|
.merge(filter_values ? { filter: filter_values } : {})
|
35
33
|
}
|
36
34
|
else
|
37
35
|
filters = (filter_values || []) + (must_not_values || []).map { |must_not_value| { not: must_not_value } }
|
38
|
-
|
39
|
-
queries = {}
|
40
|
-
.merge(must_values || search_values ? { must: (must_values || []) + (search_values || []) } : {})
|
41
|
-
.merge(should_values ? { should: should_values } : {})
|
42
|
-
|
36
|
+
queries = must_values ? { must: must_values } : {}
|
43
37
|
filters_and_queries = filters + (queries.size > 0 ? [bool: queries] : [])
|
44
38
|
|
45
39
|
res[:filter] = filters_and_queries.size > 1 ? { and: filters_and_queries } : filters_and_queries.first
|
@@ -64,8 +58,8 @@ module SearchFlip
|
|
64
58
|
unsupported_methods = [
|
65
59
|
:profile_value, :failsafe_value, :terminate_after_value, :timeout_value, :offset_value, :limit_value,
|
66
60
|
:scroll_args, :highlight_values, :suggest_values, :custom_value, :source_value, :sort_values,
|
67
|
-
:includes_values, :preload_values, :eager_load_values, :
|
68
|
-
:post_must_not_values, :
|
61
|
+
:includes_values, :preload_values, :eager_load_values, :post_must_values,
|
62
|
+
:post_must_not_values, :post_filter_values, :preference_value,
|
69
63
|
:search_type_value, :routing_value
|
70
64
|
]
|
71
65
|
|
@@ -75,10 +69,8 @@ module SearchFlip
|
|
75
69
|
end
|
76
70
|
end
|
77
71
|
|
78
|
-
aggregation.search_values = (aggregation.search_values || []) + other.search_values if other.search_values
|
79
72
|
aggregation.must_values = (aggregation.must_values || []) + other.must_values if other.must_values
|
80
73
|
aggregation.must_not_values = (aggregation.must_not_values || []) + other.must_not_values if other.must_not_values
|
81
|
-
aggregation.should_values = (aggregation.should_values || []) + other.should_values if other.should_values
|
82
74
|
aggregation.filter_values = (aggregation.filter_values || []) + other.filter_values if other.filter_values
|
83
75
|
|
84
76
|
aggregation.aggregation_values = (aggregation.aggregation_values || {}).merge(other.aggregation_values) if other.aggregation_values
|
@@ -89,7 +81,7 @@ module SearchFlip
|
|
89
81
|
target.respond_to?(name, *args)
|
90
82
|
end
|
91
83
|
|
92
|
-
|
84
|
+
def method_missing(name, *args, &block)
|
93
85
|
if target.respond_to?(name)
|
94
86
|
merge(target.send(name, *args, &block))
|
95
87
|
else
|
@@ -108,4 +100,3 @@ module SearchFlip
|
|
108
100
|
end
|
109
101
|
end
|
110
102
|
end
|
111
|
-
|
data/lib/search_flip/bulk.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
module SearchFlip
|
3
2
|
# @api private
|
4
3
|
#
|
@@ -87,7 +86,7 @@ module SearchFlip
|
|
87
86
|
#
|
88
87
|
# @see #index
|
89
88
|
|
90
|
-
|
89
|
+
def import(*args)
|
91
90
|
index(*args)
|
92
91
|
end
|
93
92
|
|
@@ -181,4 +180,3 @@ module SearchFlip
|
|
181
180
|
end
|
182
181
|
end
|
183
182
|
end
|
184
|
-
|
data/lib/search_flip/config.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
module SearchFlip
|
3
2
|
class Connection
|
4
3
|
attr_reader :base_url, :http_client, :bulk_limit, :bulk_max_mb
|
@@ -106,7 +105,10 @@ module SearchFlip
|
|
106
105
|
# @return [Hash] The raw response
|
107
106
|
|
108
107
|
def analyze(request, params = {})
|
109
|
-
http_client
|
108
|
+
http_client
|
109
|
+
.headers(accept: "application/json")
|
110
|
+
.post("#{base_url}/_analyze", json: request, params: params)
|
111
|
+
.parse
|
110
112
|
end
|
111
113
|
|
112
114
|
# Fetches information about the specified index aliases. Raises
|
@@ -122,13 +124,10 @@ module SearchFlip
|
|
122
124
|
# @return [Hash] The raw response
|
123
125
|
|
124
126
|
def get_aliases(index_name: "*", alias_name: "*")
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
.parse
|
130
|
-
|
131
|
-
Hashie::Mash.new(res)
|
127
|
+
http_client
|
128
|
+
.headers(accept: "application/json", content_type: "application/json")
|
129
|
+
.get("#{base_url}/#{index_name}/_alias/#{alias_name}")
|
130
|
+
.parse
|
132
131
|
end
|
133
132
|
|
134
133
|
# Returns whether or not the associated Elasticsearch alias already
|
@@ -159,10 +158,10 @@ module SearchFlip
|
|
159
158
|
#
|
160
159
|
# @return [Array] The raw response
|
161
160
|
|
162
|
-
def get_indices(name = "*")
|
161
|
+
def get_indices(name = "*", params: {})
|
163
162
|
http_client
|
164
163
|
.headers(accept: "application/json", content_type: "application/json")
|
165
|
-
.get("#{base_url}/_cat/indices/#{name}")
|
164
|
+
.get("#{base_url}/_cat/indices/#{name}", params: params)
|
166
165
|
.parse
|
167
166
|
end
|
168
167
|
|
@@ -210,6 +209,32 @@ module SearchFlip
|
|
210
209
|
true
|
211
210
|
end
|
212
211
|
|
212
|
+
# Freezes the specified index within Elasticsearch. Raises
|
213
|
+
# SearchFlip::ResponseError in case any errors occur
|
214
|
+
#
|
215
|
+
# @param index_name [String] The index name
|
216
|
+
#
|
217
|
+
# @return [Boolean] Returns true or raises SearchFlip::ResponseError
|
218
|
+
|
219
|
+
def freeze_index(index_name)
|
220
|
+
http_client.post("#{index_url(index_name)}/_freeze")
|
221
|
+
|
222
|
+
true
|
223
|
+
end
|
224
|
+
|
225
|
+
# Unfreezes the specified index within Elasticsearch. Raises
|
226
|
+
# SearchFlip::ResponseError in case any errors occur
|
227
|
+
#
|
228
|
+
# @param index_name [String] The index name
|
229
|
+
#
|
230
|
+
# @return [Boolean] Returns true or raises SearchFlip::ResponseError
|
231
|
+
|
232
|
+
def unfreeze_index(index_name)
|
233
|
+
http_client.post("#{index_url(index_name)}/_unfreeze")
|
234
|
+
|
235
|
+
true
|
236
|
+
end
|
237
|
+
|
213
238
|
# Updates the index settings within Elasticsearch according to the index
|
214
239
|
# settings specified. Raises SearchFlip::ResponseError in case any
|
215
240
|
# errors occur.
|
@@ -234,7 +259,10 @@ module SearchFlip
|
|
234
259
|
# @return [Hash] The index settings
|
235
260
|
|
236
261
|
def get_index_settings(index_name)
|
237
|
-
http_client
|
262
|
+
http_client
|
263
|
+
.headers(accept: "application/json")
|
264
|
+
.get("#{index_url(index_name)}/_settings")
|
265
|
+
.parse
|
238
266
|
end
|
239
267
|
|
240
268
|
# Sends a refresh request to Elasticsearch. Raises
|
@@ -338,4 +366,3 @@ module SearchFlip
|
|
338
366
|
end
|
339
367
|
end
|
340
368
|
end
|
341
|
-
|