elasticsearch-php icon indicating copy to clipboard operation
elasticsearch-php copied to clipboard

check the index exsists ,it have a error

Open MonkWang opened this issue 1 year ago • 1 comments
trafficstars

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

  • ubuntu 20.04
  • PHP7.4.30
  • ES-PHP 8.10
  • Elasticsearch 8.10

MonkWang avatar Nov 27 '23 02:11 MonkWang

@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)

ezimuel avatar Dec 11 '23 11:12 ezimuel