LoginSignup
2
0

More than 5 years have passed since last update.

ruflin/ElasticaにContent-Type: application/jsonを設定

Last updated at Posted at 2018-06-16

現象

Elasticaを利用してElasticsearchにドキュメントを突っ込むと以下が出力される

Content-Type header [application/x-www-form-urlencoded] is not supported

解決方法

単にContent-Typeをapplication/jsonで指定すれば良い。
Elastica/Transport/Httpに以下の処理を追加する。

Http.php
        $headers = [];
        // 以下の行を追加
        $headers[] = 'Content-Type: application/json';

環境

cakephp:3.6.4
cakephp/elastic-search:@stable(バージョン幾つか不明。たぶん1.0)

そもそも公式ドキュメントにある方法に倣っただけだが、
cakephp/elastic-searchの@stableバージョンが依存しているruflin/Elasticaが古い?
ただ、cakephp/elastic-searchの2.0-RC1を使うともっとおかしなことになるので、暫定対処として残します。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0