search_flip 3.9.0 → 4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84f5374ca017b59ee706e4e6e06c9739c18a83395ded6df0628b234d0e129e39
4
- data.tar.gz: 1f6e1dd1a76f69b8cb552387add7d1dfe2b367739c38a7b9260db0c9954b8e26
3
+ metadata.gz: b023bc6411647eaecfcb8f5b0fe535379974a0824d49699dd74ef867a67c69eb
4
+ data.tar.gz: 5dc4a0439f9442811f3966e86b0c6b09d09c54450a04234c3738ae0ab7935900
5
5
  SHA512:
6
- metadata.gz: 283b816aa7602cb4ffb1c981421e7fb13353158f40de052daec3c6c6700b42ff2b19eeb6accb22b8dcc29cf4589caf8c4a01edd827bc055eb97e16c6ed3ba972
7
- data.tar.gz: a63de18588ef4b93c38eb7b4bfb91135f73e027f21371ff46c053dfbadb207661008aa5b31d05ac6e62298539e73cdf5c8421bb6aff93f2369f2712724bcd7f8
6
+ metadata.gz: a5fc637e8c016531df22af678adcae60a4f4169e5f1d2215d52be0a0dff1111b849cb4d79ca36d6cbf315c8516bc51d543852ab5026339d59cb1f5d08ba356f7
7
+ data.tar.gz: 7cf9d55a9aca5d6d63401750d40bc656fcc345101d8ce92a300c24649e38810d399d43ff225611bbdd91a257d6cb15eee26a6c811974b987e92e72e67eded704
@@ -7,58 +7,28 @@ jobs:
7
7
  fail-fast: false
8
8
  matrix:
9
9
  elasticsearch:
10
- - image: plainpicture/elasticsearch:2.4.1_delete-by-query
11
- env:
12
- discovery.type: single-node
13
- xpack.security.enabled: false
14
- - image: elasticsearch:5.4
15
- env:
16
- discovery.type: single-node
17
- xpack.security.enabled: false
18
- - image: docker.elastic.co/elasticsearch/elasticsearch:6.7.0
19
- env:
20
- discovery.type: single-node
21
- xpack.security.enabled: false
22
- - image: docker.elastic.co/elasticsearch/elasticsearch:7.0.0
23
- env:
24
- discovery.type: single-node
25
- xpack.security.enabled: false
26
- - image: docker.elastic.co/elasticsearch/elasticsearch:7.11.2
27
- env:
28
- discovery.type: single-node
29
- xpack.security.enabled: false
30
- - image: docker.elastic.co/elasticsearch/elasticsearch:8.1.1
31
- env:
32
- discovery.type: single-node
33
- xpack.security.enabled: false
34
- - image: opensearchproject/opensearch:1.3.14
35
- env:
36
- discovery.type: single-node
37
- plugins.security.disabled: true
38
- - image: opensearchproject/opensearch:2.11.1
39
- env:
40
- discovery.type: single-node
41
- plugins.security.disabled: true
42
- - image: opensearchproject/opensearch:2.13.0
43
- env:
44
- discovery.type: single-node
45
- DISABLE_SECURITY_PLUGIN: true
10
+ - plainpicture/elasticsearch:2.4.1_delete-by-query
11
+ - elasticsearch:5.4
12
+ - docker.elastic.co/elasticsearch/elasticsearch:6.7.0
13
+ - docker.elastic.co/elasticsearch/elasticsearch:7.0.0
14
+ - docker.elastic.co/elasticsearch/elasticsearch:7.9.0
46
15
  ruby:
16
+ - 2.5
17
+ - 2.6
47
18
  - 2.7
48
- - 3.0
49
- - 3.1
50
- - 3.2
51
19
  services:
52
20
  elasticsearch:
53
- image: ${{ matrix.elasticsearch.image }}
54
- env: ${{ matrix.elasticsearch.env }}
21
+ image: ${{ matrix.elasticsearch }}
22
+ env:
23
+ discovery.type: single-node
55
24
  ports:
56
25
  - 9200:9200
57
26
  steps:
58
27
  - uses: actions/checkout@v1
59
- - uses: ruby/setup-ruby@v1
28
+ - uses: actions/setup-ruby@v1
60
29
  with:
61
30
  ruby-version: ${{ matrix.ruby }}
62
31
  - run: bundle
32
+ - run: sleep 10
63
33
  - run: bundle exec rspec
64
34
  - run: bundle exec rubocop
data/.rubocop.yml CHANGED
@@ -1,15 +1,11 @@
1
1
  AllCops:
2
2
  NewCops: enable
3
- TargetRubyVersion: 2.5
4
- SuggestExtensions: false
3
+ TargetRubyVersion: 2.4
5
4
 
6
- Gemspec/RequireMFA:
5
+ Gemspec/RequiredRubyVersion:
7
6
  Enabled: false
8
7
 
9
- Layout/EmptyLineBetweenDefs:
10
- EmptyLineBetweenClassDefs: false
11
-
12
- Gemspec/RequiredRubyVersion:
8
+ Style/CaseLikeIf:
13
9
  Enabled: false
14
10
 
15
11
  Style/ExplicitBlockArgument:
data/CHANGELOG.md CHANGED
@@ -1,63 +1,13 @@
1
1
 
2
2
  # CHANGELOG
3
3
 
4
- ## v3.9.0
4
+ ## v4.0.0
5
5
 
6
- * Allow to configure the elasticsearch version no matter which elasticsearch
7
- version is actually in use. The version information is needed to support
8
- version dependent features. Please note that manually configuring the version
9
- is usually not need as the version by default is determined by sending one
10
- request to elasticsearch.
11
-
12
- ```ruby
13
- SearchFlip::Config[:version] = { number: "8.1.1" }
14
- SearchFlip::Config[:version] = { number: "2.13", distribution: "opensearch" }
15
- ```
16
-
17
- ## v3.8.0
18
-
19
- * Support Opensearch 1.x and 2.x
20
-
21
- ## v3.7.2
22
-
23
- * Fix wrong AWS signatures by generating the json before passing it to http-rb
24
-
25
- ## v3.7.1
26
-
27
- * Fix thread-safety issue of http-rb
28
-
29
- ## v3.7.0
30
-
31
- * Add `SearchFlip::Connection#bulk` to allow more clean bulk indexing to
32
- multiple indices at once
33
-
34
- ## v3.6.0
35
-
36
- * Support Elasticsearch v8
37
-
38
- ## v3.5.0
39
-
40
- * Add `SearchFlip::Criteria#http_timeout` to allow specifying timeouts on
41
- a query level
42
-
43
- ## v3.4.0
44
-
45
- * Expose `Http#timeout` via `SearchFlip::HTTPClient`
46
-
47
- ## v3.3.0
48
-
49
- * Update httprb
50
- * Changed oj default options
51
- * Allow to set oj json options
52
-
53
- ## v3.2.1
54
-
55
- * Fix `refresh` having a empty body breaking in elasticsearch 7.11
56
-
57
- ## v3.2.0
58
-
59
- * Fix `index_scope` not being passed in `each_record` without block
60
- * Added `SearchFlip::Criteria#match_none`
6
+ * [BREAKING] For performance reasons, `SearchFlip::Result` now no longer
7
+ inherits `Hashie::Mash`
8
+ * It no longer supports symbol based access like `result[:id]`
9
+ * It no longer supports question mark methods like `result.title?`
10
+ * It no longer supports method based assignment like `result.some_key = "value"`
61
11
 
62
12
  ## v3.1.2
63
13
 
data/Gemfile CHANGED
@@ -2,18 +2,4 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.2.2")
6
- gem "activerecord", ">= 3.0", "< 5"
7
- else
8
- gem "activerecord", ">= 3.0"
9
- end
10
-
11
- gem "aws-sdk-core"
12
- gem "bundler"
13
- gem "factory_bot"
14
- gem "rake"
15
- gem "rspec"
16
- gem "rubocop"
17
- gem "sqlite3", "~> 1.4"
18
- gem "timecop"
19
- gem "webmock"
5
+ gem "activerecord", "< 5" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.2.2")
data/README.md CHANGED
@@ -9,9 +9,8 @@
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 2.x, 5.x, 6.x, 7.x and 8.x as well as
13
- Opensearch 1.x and 2.x. Check section [Feature Support](#feature-support) for
14
- version dependent features.
12
+ SearchFlip supports Elasticsearch 2.x, 5.x, 6.x, 7.x. Check section
13
+ [Feature Support](#feature-support) for version dependent features.
15
14
 
16
15
  ```ruby
17
16
  CommentIndex.search("hello world", default_field: "title").where(visible: true).aggregate(:user_id).sort(id: "desc")
@@ -52,7 +51,7 @@ CommentIndex.search("hello world").where(available: true).sort(id: "desc").aggre
52
51
 
53
52
  ```
54
53
 
55
- Finally, SearchFlip comes with a minimal set of dependencies.
54
+ Finally, SearchFlip comes with a minimal set of dependencies (http-rb and oj only).
56
55
 
57
56
  ## Reference Docs
58
57
 
@@ -98,16 +97,6 @@ Available config options are:
98
97
  * `auto_refresh` tells SearchFlip to automatically refresh an index after
99
98
  import, index, delete, etc operations. This is e.g. useful for testing, etc.
100
99
  Defaults to false.
101
- * `version` allows to configure the elasticsearch version no matter which
102
- elasticsearch version is actually in use. The version information is needed to
103
- support version dependent features. Please note that manually configuring the
104
- version is usually not need as the version by default is determined by sending
105
- one request to elasticsearch.
106
-
107
- ```ruby
108
- SearchFlip::Config[:version] = { number: "8.1.1" }
109
- SearchFlip::Config[:version] = { number: "2.13", distribution: "opensearch" }
110
- ```
111
100
 
112
101
  ## Usage
113
102
 
@@ -429,14 +418,6 @@ Simply matches all documents:
429
418
  CommentIndex.match_all
430
419
  ```
431
420
 
432
- * `match_none`
433
-
434
- Simply matches none documents at all:
435
-
436
- ```ruby
437
- CommentIndex.match_none
438
- ```
439
-
440
421
  * `all`
441
422
 
442
423
  Simply returns the criteria as is or an empty criteria when called on the index
@@ -493,8 +474,8 @@ end
493
474
  ```
494
475
 
495
476
  Generally, aggregation results returned by Elasticsearch are returned as a
496
- `SearchFlip::Result`, which basically is a `Hashie::Mash`, such that you can
497
- access them via:
477
+ `SearchFlip::Result`, which basically is a Hash with method-like access, such
478
+ that you can access them via:
498
479
 
499
480
  ```ruby
500
481
  query.aggregations(:username)["mrkamel"].revenue.value
@@ -709,14 +690,6 @@ Specify a timeout to limit query processing time:
709
690
  CommentIndex.timeout("3s").execute
710
691
  ```
711
692
 
712
- * `http_timeout`
713
-
714
- Specify a http timeout for the request which will be send to Elasticsearch:
715
-
716
- ```ruby
717
- CommentIndex.http_timeout(3).execute
718
- ```
719
-
720
693
  * `terminate_after`
721
694
 
722
695
  Activate early query termination to stop query processing after the specified
@@ -775,7 +748,7 @@ end
775
748
  This allows to use different clusters per index e.g. when migrating indices to
776
749
  new versions of Elasticsearch.
777
750
 
778
- You can specify basic auth, additional headers, request timeouts, etc via:
751
+ You can specify basic auth, additional headers, etc via:
779
752
 
780
753
  ```ruby
781
754
  http_client = SearchFlip::HTTPClient.new
@@ -792,9 +765,6 @@ http_client = http_client.via("proxy.host", 8080)
792
765
  # Custom headers
793
766
  http_client = http_client.headers(key: "value")
794
767
 
795
- # Timeouts
796
- http_client = http_client.timeout(20)
797
-
798
768
  SearchFlip::Connection.new(base_url: "...", http_client: http_client)
799
769
  ```
800
770
 
@@ -863,7 +833,7 @@ performance tracing, etc.
863
833
  To use instrumentation, configure the instrumenter:
864
834
 
865
835
  ```ruby
866
- SearchFlip::Config[:instrumenter] = ActiveSupport::Notifications
836
+ SearchFlip::Config[:instrumenter] = ActiveSupport::Notifications.notifier
867
837
  ```
868
838
 
869
839
  Subsequently, you can subscribe to notifcations for `request.search_flip`:
@@ -904,52 +874,57 @@ Thus, if your ORM supports `.find_each`, `#id` and `#where` you are already
904
874
  good to go. Otherwise, simply add your custom implementation of those methods
905
875
  that work with whatever ORM you use.
906
876
 
907
- ## JSON
877
+ ## Date and Timestamps in JSON
908
878
 
909
- SearchFlip is using the [Oj gem](https://github.com/ohler55/oj) to generate
910
- JSON. More concretely, SearchFlip is using:
879
+ Elasticsearch requires dates and timestamps to have one of the formats listed
880
+ here: [https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html#strict-date-time](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html#strict-date-time).
881
+
882
+ However, `JSON.generate` in ruby by default outputs something like:
911
883
 
912
884
  ```ruby
913
- Oj.dump({ key: "value" }, mode: :custom, use_to_json: true, time_format: :xmlschema, bigdecimal_as_decimal: false)
885
+ JSON.generate(time: Time.now.utc)
886
+ # => "{\"time\":\"2018-02-22 18:19:33 UTC\"}"
914
887
  ```
915
888
 
916
- The `use_to_json` option is used for maximum compatibility, most importantly
917
- when using rails `ActiveSupport::TimeWithZone` timestamps, which `oj` can not
918
- serialize natively. However, `use_to_json` adds performance overhead. You can
919
- change the json options via:
889
+ This format is not compatible with Elasticsearch by default. If you're on
890
+ Rails, ActiveSupport adds its own `#to_json` methods to `Time`, `Date`, etc.
891
+ However, ActiveSupport checks whether they are used in combination with
892
+ `JSON.generate` or not and adapt:
920
893
 
921
894
  ```ruby
922
- SearchFlip::Config[:json_options] = {
923
- mode: :custom,
924
- use_to_json: false,
925
- time_format: :xmlschema,
926
- bigdecimal_as_decimal: false
927
- }
895
+ Time.now.utc.to_json
896
+ => "\"2018-02-22T18:18:22.088Z\""
897
+
898
+ JSON.generate(time: Time.now.utc)
899
+ => "{\"time\":\"2018-02-22 18:18:59 UTC\"}"
928
900
  ```
929
901
 
930
- However, you then have to convert timestamps manually for indexation via e.g.:
902
+ SearchFlip is using the [Oj gem](https://github.com/ohler55/oj) to generate
903
+ JSON. More concretely, SearchFlip is using:
931
904
 
932
905
  ```ruby
933
- class MyIndex
934
- # ...
906
+ Oj.dump({ key: "value" }, mode: :custom, use_to_json: true)
907
+ ```
935
908
 
936
- def self.serialize(model)
937
- {
938
- # ...
909
+ This mitigates the issues if you're on Rails:
939
910
 
940
- created_at: model.created_at.to_time
941
- }
942
- end
943
- end
911
+ ```ruby
912
+ Oj.dump(Time.now, mode: :custom, use_to_json: true)
913
+ # => "\"2018-02-22T18:21:21.064Z\""
944
914
  ```
945
915
 
946
- Please check out the oj docs for more details.
916
+ However, if you're not on Rails, you need to add `#to_json` methods to `Time`,
917
+ `Date` and `DateTime` to get proper serialization. You can either add them on
918
+ your own, via other libraries or by simply using:
919
+
920
+ ```ruby
921
+ require "search_flip/to_json"
922
+ ```
947
923
 
948
924
  ## Feature Support
949
925
 
950
926
  * for Elasticsearch 2.x, the delete-by-query plugin is required to delete
951
927
  records via queries
952
- * `#match_none` is only available with Elasticsearch >= 5
953
928
  * `#track_total_hits` is only available with Elasticsearch >= 7
954
929
 
955
930
  ## Keeping your Models and Indices in Sync
@@ -981,6 +956,7 @@ SearchFlip is using Semantic Versioning: [SemVer](http://semver.org/)
981
956
 
982
957
  * Elasticsearch: [https://www.elastic.co/](https://www.elastic.co/)
983
958
  * Reference Docs: [http://www.rubydoc.info/github/mrkamel/search_flip](http://www.rubydoc.info/github/mrkamel/search_flip)
959
+ * Travis: [http://travis-ci.org/mrkamel/search_flip](http://travis-ci.org/mrkamel/search_flip)
984
960
  * will_paginate: [https://github.com/mislav/will_paginate](https://github.com/mislav/will_paginate)
985
961
  * kaminari: [https://github.com/kaminari/kaminari](https://github.com/kaminari/kaminari)
986
962
  * Oj: [https://github.com/ohler55/oj](https://github.com/ohler55/oj)
data/UPDATING.md CHANGED
@@ -1,6 +1,46 @@
1
1
 
2
2
  # Updating from previous SearchFlip versions
3
3
 
4
+ ## Update 3.x to 4.x
5
+
6
+ **[BREAKING]** For performance reasons, `SearchFlip::Result` no longer
7
+ inherits `Hashie::Mash`
8
+
9
+ * It no longer supports symbol based access like `result[:id]`
10
+
11
+ 2.x:
12
+
13
+ ```ruby
14
+ CommentIndex.match_all.results.first[:id]
15
+ CommentIndex.aggregate(:tags).aggregations(:tags).values.first[:doc_count]
16
+ ```
17
+
18
+ 3.x
19
+
20
+ ```ruby
21
+ CommentIndex.match_all.results.first["id"] # or .id
22
+ CommentIndex.aggregate(:tags).aggregations(:tags).values.first["doc_count"] # or .doc_count
23
+ ```
24
+
25
+ * It no longer supports question mark methods like `result.title?`
26
+
27
+ 2.x:
28
+
29
+ ```ruby
30
+ CommentIndex.match_all.results.first.is_published?
31
+ ```
32
+
33
+ 3.x
34
+
35
+ ```ruby
36
+ CommentIndex.match_all.results.first.is_published == true
37
+ ```
38
+
39
+ * It no longer supports method based assignment like `result.some_key = "value"`.
40
+
41
+ However, this should not have any practical implications, as changing the
42
+ results is not considered to be a common use case.
43
+
4
44
  ## Update 2.x to 3.x
5
45
 
6
46
  * **[BREAKING]** No longer pass multiple arguments to `#must`, `#must_not`,
data/docker-compose.yml CHANGED
@@ -4,6 +4,5 @@ services:
4
4
  image: $ES_IMAGE
5
5
  environment:
6
6
  - discovery.type=single-node
7
- - xpack.security.enabled=false
8
7
  ports:
9
8
  - 9200:9200
@@ -30,7 +30,7 @@ module SearchFlip
30
30
  res[:aggregations] = aggregation_values if aggregation_values
31
31
 
32
32
  if must_values || must_not_values || filter_values
33
- if target.connection.distribution || target.connection.version.to_i >= 2
33
+ if target.connection.version.to_i >= 2
34
34
  res[:filter] = {
35
35
  bool: {}
36
36
  .merge(must_values ? { must: must_values } : {})
@@ -37,6 +37,7 @@ module SearchFlip
37
37
  }
38
38
 
39
39
  signature_request[:body] = options[:body] if options.key?(:body)
40
+ signature_request[:body] = options[:json].respond_to?(:to_str) ? options[:json] : JSON.generate(options[:json]) if options[:json]
40
41
 
41
42
  signature = signer.sign_request(signature_request)
42
43
 
@@ -143,12 +143,12 @@ module SearchFlip
143
143
 
144
144
  return if options[:raise] == false
145
145
 
146
- parsed_response = SearchFlip::JSON.parse(response.to_s)
146
+ parsed_response = response.parse
147
147
 
148
148
  return unless parsed_response["errors"]
149
149
 
150
150
  parsed_response["items"].each do |item|
151
- item.each_value do |element|
151
+ item.each do |_, element|
152
152
  status = element["status"]
153
153
 
154
154
  next if status.between?(200, 299)
@@ -5,12 +5,6 @@ module SearchFlip
5
5
  bulk_limit: 1_000,
6
6
  bulk_max_mb: 100,
7
7
  auto_refresh: false,
8
- instrumenter: NullInstrumenter.new,
9
- json_options: {
10
- mode: :custom,
11
- use_to_json: true,
12
- time_format: :xmlschema,
13
- bigdecimal_as_decimal: false
14
- }
8
+ instrumenter: NullInstrumenter.new
15
9
  }
16
10
  end