How can I know if a desired value exists or not?
What do you mean about a "desiderad value"?
If you mean if an index exists in Elasticsearch you can use the indices.exists API, as follows:
$index = 'insert-index-name';
$result = $client->indices()->exists([ 'index' => $index ]);
printf ("Index %s %s", $index, $result ? 'exists' : 'does not exist');
Instead, if you mean if a document ID exists, you can use the exists API, as follows:
$index = 'insert-index-name';
$documentId = 'insert-document-id';
$result = $client->exists([
'index' => $index,
'id' => $documentId
]);
printf (
"Document ID %s with index %s %s",
$index,
$documentId,
$result ? 'exists' : 'does not exist'
);
thanks
Most helpful comment
What do you mean about a "desiderad value"?
If you mean if an index exists in Elasticsearch you can use the
indices.existsAPI, as follows:Instead, if you mean if a document ID exists, you can use the
existsAPI, as follows: