mattporritt / moodle-search_elastic

An Elasticsearch engine plugin for Moodle's Global Search
https://moodle.org/plugins/search_elastic
GNU General Public License v3.0
16 stars 13 forks source link

Add support for Elastic Cloud #101

Closed dmitriim closed 1 year ago

dmitriim commented 1 year ago

Elastic search could be hidden behind Elastic cloud APIs https://www.elastic.co/elasticsearch/

There is some docs for using PHP client https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/connecting.html

I don't think we should switch to new SDK. However, to get the current code working with Elastic cloud we would need to modify it a bit and get few new settings on board.

Elastic Cloud SDK parses a cloud ID to build a host

    /**
     * Return the URL of Elastic Cloud from the Cloud ID
     */
    private function parseElasticCloudId(string $cloudId): string
    {
        try {
            list($name, $encoded) = explode(':', $cloudId);
            list($uri, $uuids)    = explode('$', base64_decode($encoded));
            list($es,)            = explode(':', $uuids);

            return sprintf("https://%s.%s", $es, $uri);
        } catch (Throwable $t) {
            throw new Exception\CloudIdParseException(
                'Cloud ID not valid'
            );
        }
    }

We don't have to do the same as host URL could be grabbed from the cloud UI console. E.g. https://7fbb410d547049028abb975dc254cfeb.eastus2.azure.elastic-cloud.com

To be able to call this end point you'd need to have ApiKey and pass it as a header 'Authorization: ApiKey <Replace_with_created_API_key>'

[ ] Modify settings and add API key field there [ ] If configured use this API Key in all request to an end point as a header [ ] Test indexing and search using Elastic cloud . [ ] Update README

dmitriim commented 1 year ago

It doesn't look like request signing will work with elastic cloud. We would need somehow to deal with that in the settings.