The AJAX, which is part of Elasticpress, looks like this
$.ajax( {
url: epas.endpointUrl,
type: 'GET',
dataType: 'json',
crossDomain: true,
data: JSON.stringify( query )
} );
Additionally I registered my endpoint
add_action( 'rest_api_init', function ( $data ) {
register_rest_route( 'elasticpress', '/autosuggest/', [
'methods' => 'GET',
'callback' => 'ep_autosuggest'
] );
} );
The callback looks like this
function ep_autosuggest( $data ) {
// Elasticsearch PHP Client
$client = ClientBuilder::create()->build();
$params = [
'index' => 'index',
'type' => 'post',
'body' => $data
];
$response = $client->search( $params );
return $response;
}
The different parts work as they should. I’m struggling with getting the data from the passed object. Any ideas?