elasticsearch-php
elasticsearch-php copied to clipboard
check the index exsists ,it have a error
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 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)