Delete an elasticsearch document
-
Hello,
I have a problem when I delete a post from the website.
The post still appears in search results probably because is also stored in the elasticsearch database.
Do you have any idea how I can delete that index?
Looking at the code in ElasticPress I saw the below function, but I’m not sure if I can do something from the WordPress interface.
public function delete_document( $index, $type, $document_id, $blocking = true ) { if ( version_compare( $this->get_elasticsearch_version(), '7.0', '<' ) ) { $path = $index . '/' . $type . '/' . $document_id; } else { $path = $index . '/_doc/' . $document_id; } $request_args = [ 'method' => 'DELETE', 'timeout' => 15, 'blocking' => $blocking, ]; $request = $this->remote_request( $path, $request_args, [], 'delete' ); if ( ! is_wp_error( $request ) ) { $response_body = wp_remote_retrieve_body( $request ); $response = json_decode( $response_body, true ); if ( ! empty( $response['found'] ) ) { return true; } } return false; }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Delete an elasticsearch document’ is closed to new replies.