diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e618ec7e8..de0dfcc22b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ **See the full release notes on the official documentation website: https://www.elastic.co/docs/release-notes/elasticsearch/clients/ruby** +# Unreleased + +* Removes the `multi_json` and `oj` gems in favor of the standard Ruby `json` gem, which is now the default serializer implementation. + # 9.4.3 * Fixes header conflict when using Elasticsearch Serverless. [Pull Request](https://github.com/elastic/elasticsearch-ruby/pull/2984) diff --git a/docs/examples/rabbitmq/Gemfile b/docs/examples/rabbitmq/Gemfile index 91c1bdaac8..3f91f33d33 100644 --- a/docs/examples/rabbitmq/Gemfile +++ b/docs/examples/rabbitmq/Gemfile @@ -21,5 +21,4 @@ gem 'elasticsearch' gem 'bunny' -gem 'multi_json' -gem 'oj' +gem 'json' diff --git a/docs/examples/rabbitmq/consumer-publisher.rb b/docs/examples/rabbitmq/consumer-publisher.rb index 2a3bf9a11e..45e3cd2a62 100644 --- a/docs/examples/rabbitmq/consumer-publisher.rb +++ b/docs/examples/rabbitmq/consumer-publisher.rb @@ -23,8 +23,7 @@ # $ bundle exec ruby consume-publish.rb # -require 'multi_json' -require 'oj' +require 'json' require 'elasticsearch' @@ -43,12 +42,12 @@ elasticsearch.indices.delete index: 'rabbit' rescue nil queue.subscribe do |delivery_info, metadata, payload| - hash = MultiJson.load(payload) + hash = JSON.load(payload) elasticsearch.index index: 'rabbit', type: 'event', id: hash.delete(:id), body: hash end (1..10).each do |i| - exchange.publish MultiJson.dump({id: i, title: "Test #{i}"}), routing_key: queue.name + exchange.publish JSON.dump({id: i, title: "Test #{i}"}), routing_key: queue.name end sleep 1.0 @@ -58,7 +57,7 @@ [:INT, :TERM].each do |signal| trap(signal) { puts "\nExiting..."; exit } end while input = gets - exchange.publish MultiJson.dump({title: input.chomp}), routing_key: queue.name unless input =~ /^\s*$/ + exchange.publish JSON.dump({title: input.chomp}), routing_key: queue.name unless input =~ /^\s*$/ end connection.close diff --git a/docs/reference/advanced-config.md b/docs/reference/advanced-config.md index c045a91d4b..85c28a01f0 100644 --- a/docs/reference/advanced-config.md +++ b/docs/reference/advanced-config.md @@ -279,7 +279,7 @@ Elasticsearch::Client.new hosts: ['x1.search.org', 'x2.search.org'], selector_cl ## Serializer Implementations [serializer-implementations] -By default, the [MultiJSON](https://rubygems.org/gems/multi_json) library is used as the serializer implementation, and it picks up the "right" adapter based on gems available. +By default, the standard `JSON` library is used as the serializer implementation. The serialization component is pluggable, though, so you can write your own by including the `Elastic::Transport::Transport::Serializer::Base` module, implementing the required contract, and passing it to the client as the `serializer_class` or `serializer` parameter. diff --git a/docs/reference/api.md b/docs/reference/api.md index 261413b45c..c36d3999fa 100644 --- a/docs/reference/api.md +++ b/docs/reference/api.md @@ -103,7 +103,7 @@ When you want to mix the library with your own client, it must conform to the fo A simple client could look like this (*with a dependency on `active_support` to parse the query params*): ```rb -require 'multi_json' +require 'json' require 'faraday' require 'elasticsearch/api' @@ -118,7 +118,7 @@ class MySimpleClient CONNECTION.run_request \ method.downcase.to_sym, path_with_params(path, params), - ( body ? MultiJson.dump(body): nil ), + ( body ? JSON.dump(body): nil ), {'Content-Type' => 'application/json'} end @@ -201,7 +201,7 @@ mash.hits.hits.first._source.title ### Using a Custom JSON Serializer [_using_a_custom_json_serializer] -The library uses the [MultiJson](https://rubygems.org/gems/multi_json/) gem by default but allows you to set a custom JSON library, provided it uses the standard `load/dump` interface: +The library uses the standard `JSON` library by default but allows you to set a custom JSON library, provided it uses the standard `load/dump` interface: ```rb Elasticsearch::API.settings[:serializer] = JrJackson::Json diff --git a/elasticsearch-api/elasticsearch-api.gemspec b/elasticsearch-api/elasticsearch-api.gemspec index 2424635306..eefd5d1286 100644 --- a/elasticsearch-api/elasticsearch-api.gemspec +++ b/elasticsearch-api/elasticsearch-api.gemspec @@ -44,7 +44,7 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 2.6' # For compatibility with JRuby 9.3 s.add_dependency 'base64' - s.add_dependency 'multi_json' + s.add_dependency 'json', '~> 2.19' s.add_development_dependency 'ansi' s.add_development_dependency 'bundler' diff --git a/elasticsearch-api/lib/elasticsearch/api.rb b/elasticsearch-api/lib/elasticsearch/api.rb index 33d5aecde8..236eb926de 100644 --- a/elasticsearch-api/lib/elasticsearch/api.rb +++ b/elasticsearch-api/lib/elasticsearch/api.rb @@ -16,7 +16,7 @@ # under the License. require 'cgi/escape' -require 'multi_json' +require 'json' require 'elasticsearch/api/version' require 'elasticsearch/api/utils' require 'elasticsearch/api/response' @@ -29,7 +29,7 @@ module Elasticsearch module API include Elasticsearch::API::Actions - DEFAULT_SERIALIZER = MultiJson + DEFAULT_SERIALIZER = JSON HTTP_GET = 'GET'.freeze HTTP_HEAD = 'HEAD'.freeze diff --git a/elasticsearch-api/spec/unit/actions/hashie_spec.rb b/elasticsearch-api/spec/unit/actions/hashie_spec.rb index afba03698f..8d9c149a43 100644 --- a/elasticsearch-api/spec/unit/actions/hashie_spec.rb +++ b/elasticsearch-api/spec/unit/actions/hashie_spec.rb @@ -80,7 +80,7 @@ end let(:response) do - Hashie::Mash.new(MultiJson.load(json)) + Hashie::Mash.new(JSON.load(json)) end it 'wraps the response' do diff --git a/elasticsearch-api/spec/unit/api_spec.rb b/elasticsearch-api/spec/unit/api_spec.rb index 06aebc88c2..562d19803b 100644 --- a/elasticsearch-api/spec/unit/api_spec.rb +++ b/elasticsearch-api/spec/unit/api_spec.rb @@ -24,7 +24,7 @@ end it 'has a default serializer' do - expect(Elasticsearch::API.serializer).to eq(MultiJson) + expect(Elasticsearch::API.serializer).to eq(JSON) end context 'when settings are changed' do diff --git a/elasticsearch-api/spec/unit/perform_request_spec.rb b/elasticsearch-api/spec/unit/perform_request_spec.rb index 508034bb6c..aa351ed8fe 100644 --- a/elasticsearch-api/spec/unit/perform_request_spec.rb +++ b/elasticsearch-api/spec/unit/perform_request_spec.rb @@ -29,7 +29,7 @@ class EndpointSpec def initialize(filepath) @path = Pathname(filepath) - json = MultiJson.load(File.read(@path)) + json = JSON.load(File.read(@path)) @endpoint_name = json.keys.first full_namespace = parse_full_namespace diff --git a/elasticsearch-api/spec/unit/utils_spec.rb b/elasticsearch-api/spec/unit/utils_spec.rb index 93680796cb..7acdf4ef50 100644 --- a/elasticsearch-api/spec/unit/utils_spec.rb +++ b/elasticsearch-api/spec/unit/utils_spec.rb @@ -186,11 +186,11 @@ end let(:header) do - MultiJson.load(lines.first) + JSON.load(lines.first) end let(:data_string) do - MultiJson.load(lines.last) + JSON.load(lines.last) end it 'does not mutate the input' do diff --git a/scripts/benchmark-vectors/Gemfile b/scripts/benchmark-vectors/Gemfile index cdddd66f2e..eae4dbf400 100644 --- a/scripts/benchmark-vectors/Gemfile +++ b/scripts/benchmark-vectors/Gemfile @@ -23,5 +23,5 @@ else end gem 'elasticsearch-api', path: File.expand_path('../../elasticsearch-api', __dir__) gem 'elasticsearch', path: File.expand_path('../../elasticsearch', __dir__) -gem 'multi_json' +gem 'json' gem 'rake' diff --git a/scripts/benchmark-vectors/app.rb b/scripts/benchmark-vectors/app.rb index 2ef1168568..15b2241b71 100644 --- a/scripts/benchmark-vectors/app.rb +++ b/scripts/benchmark-vectors/app.rb @@ -17,7 +17,7 @@ inicio = Time.now require 'jrjackson' if defined?(JRUBY_VERSION) -require 'multi_json' +require 'json' require 'elasticsearch' require 'elasticsearch/helpers/bulk_helper' @@ -66,7 +66,7 @@ def benchmark(data, chunk_size, vector: false) bulk_helper = Elasticsearch::Helpers::BulkHelper.new(@client, @index) start = Time.now 20.times do # repeat the dataset until 20k reached (1_000 * 20) - json = MultiJson.load("[#{data}]") + json = JSON.load("[#{data}]") json.each_slice(chunk_size) do |slice| slice.map { |j| j['emb'] = @client.pack_dense_vector(j['emb']) } if vector bulk_helper.ingest(slice)