elastic / elastic/elasticsearch-ruby

MultiJson deprecation warnings emitted from Elasticsearch::API.serializer with multi_json >= 1.21

オープン
#3,055 コメント 0 件 リアクション 6 件 担当者 0 名 GitHub で見る
主要言語
Ruby
スター
2k
フォーク
615
PR マージ指標
30日以内にマージされた PR はありません

説明

**Describe the bug/error/problem**

`multi_json` 1.21.0 deprecated the legacy `MultiJson` constant in favor of `MultiJSON`. `elasticsearch-api` still references the legacy constant as its default serializer, in `lib/elasticsearch/api.rb` (still present on `main`, commit `73acacb`):

```ruby
DEFAULT_SERIALIZER = MultiJson
```

Every call that goes through `Elasticsearch::API.serializer` (e.g. `Utils.__bulkify` for bulk requests, `msearch`, `msearch_template`, `fleet.msearch`) routes through `multi_json`'s deprecation shim and emits, once per process:

```
The MultiJson constant is deprecated and will be removed in v2.0. Use MultiJSON instead.
MultiJSON.dump is deprecated and will be removed in v2.0. Use MultiJSON.generate instead.
```

The second warning appears because `dump`/`load` are themselves deprecated aliases on the new `MultiJSON` module (the current API is `generate`/`parse`).

This is the same problem that was reported for the transport layer in elastic/elastic-transport-ruby#125 and fixed in `elastic-transport` 8.5.3: with an up-to-date transport, `elasticsearch-api` is now the remaining source of these warnings.

**To Reproduce**

```ruby
require 'elasticsearch' # with multi_json >= 1.21 installed

Warning[:deprecated] = true
Elasticsearch::API.serializer.dump({ a: 1 })
# => The MultiJson constant is deprecated and will be removed in v2.0. Use MultiJSON instead.
# => MultiJSON.dump is deprecated and will be removed in v2.0. Use MultiJSON.generate instead.
```

In a real application the warnings appear at runtime on the first bulk indexing request (or any other API that serializes a payload through `Elasticsearch::API.serializer`).

**Expected behavior**

No deprecation warnings: the serializer should use the `MultiJSON` constant and its current API (`generate`/`parse`) when `multi_json >= 1.21` is loaded, falling back to `MultiJson.dump`/`MultiJson.load` on older versions. Checking `defined?(::MultiJSON)` handles both cases without version sniffing.

**Your Environment (please complete the following information):**

- Operating System: macOS 15
- Ruby Version: Ruby MRI 4.0.1
- Elasticsearch client version: `elasticsearch` / `elasticsearch-api` 8.19.3 (the legacy constant is also still referenced on `main`)
- `multi_json` version: 1.21.1
- Elasticsearch version: 8.19

**Additional context**

A workaround for applications is to inject a custom serializer:

```ruby
module MultiJsonSerializerShim
def self.dump(object, options = {})
MultiJSON.generate(object, options)
end

def self.load(string, options = {})
MultiJSON.parse(string, options)
end
end
Elasticsearch::API.settings[:serializer] = MultiJsonSerializerShim
```
---
Issue opened with the help of [Claude Code](https://claude.com/claude-code).

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。