elastic / elasticsearch-php

Official PHP client for Elasticsearch.
https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html
MIT License
5.27k stars 965 forks source link

check the index exsists ,it have a error #1381

Closed MonkWang closed 5 months ago

MonkWang commented 10 months ago

Summary of problem or feature request

when i want to check the index exsist, then it's reported "Not a valid Json: Syntax error"

Code snippet of problem

$response = $this->client->indices()->exists($params)->asArray();

System details

ezimuel commented 9 months ago

@MonkWang the exists() endpoint return true or false using the asBool() function. This is because the Elasticsearch exists API does not return a body and the asArray() returns an error. You should use as follows:

$params = [ 'index' => 'not_existing_index'];
$response = $client->indices()->exists($params)->asBool();
var_dump($response); // bool(false)