1

I am trying to run a project that uses elasticsearch on my computer. But at the point that the API. Queries something from elasticsearch I get the following error and the query does not execute:

Elasticsearch\Common\Exceptions\RuntimeException: Failed to JSON encode: 5 in file /Users/sobhan.bagheri/projects/laravel/regionsdelen-api/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Serializers/SmartSerializer.php on line 33

I am using: laravel framework with valet - php7.1 - elasticsearch 6.1.2 - and elasticsearch/elasticsearch:v6.0.1 for the driver.

I tried everything like changing elasticsearch to newer or older versions. Changing the way of the client connects to elasticsearch and also changed versions of the elasticsearch/elasticsearch driver but nothing seems to work.

btw: those versions I mentioned are the exact ones running on another machine without this error.

P.S: This error only occurres when I query a swedish character.

TheDevWay
  • 1,363
  • 1
  • 16
  • 45

2 Answers2

4

I also was facing the same problem. For me, the issue was that string contained special character which creates an issue while encoding to JSON so try this.

$array= array_map('utf8_encode', $array);

Hopefully, this will work for you.

int_ashish
  • 121
  • 1
  • 5
1

I had the same problem, my problem was due to using substr() function on strings before inserting in elasticSearch index then I replaced it with mb_substr(string, start, length,'utf8') function and the problem solved.

Kibo
  • 870
  • 1
  • 15
  • 30