Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 1 addition & 2 deletions docs/examples/rabbitmq/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ gem 'elasticsearch'

gem 'bunny'

gem 'multi_json'
gem 'oj'
gem 'json'
9 changes: 4 additions & 5 deletions docs/examples/rabbitmq/consumer-publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
# $ bundle exec ruby consume-publish.rb
#

require 'multi_json'
require 'oj'
require 'json'

require 'elasticsearch'

Expand All @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion docs/reference/advanced-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions docs/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch-api/elasticsearch-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions elasticsearch-api/lib/elasticsearch/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch-api/spec/unit/actions/hashie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch-api/spec/unit/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch-api/spec/unit/perform_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions elasticsearch-api/spec/unit/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/benchmark-vectors/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 2 additions & 2 deletions scripts/benchmark-vectors/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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)
Expand Down