carlalexander / debops-wordpress

Your superpowered WordPress server in three commands.
GNU General Public License v3.0
439 stars 65 forks source link

ElasticPress Autosuggest #192

Closed yuriolive closed 6 years ago

yuriolive commented 6 years ago

I'm trying to enable ElaticPress Autosuggest but it requires a URL to be exposed. There is any configuration in debops wordpress to expose the url or to add this configuration in nginx? Thks

image

    # Elasticsearch endpoint
    location /es-search {

        # only allow things to hit the _autosuggest API
        # change the `_endpoint` to be whatever you'd like to restrict usage to
        location ~* (.*)_suggest$ {

            # only allow POST requests
            limit_except POST {
                deny all;
            }

            # Perform our request
            rewrite ^/es-search(.*) $1 break;
            proxy_set_header Host $host;

            # Use the URL of the server here
            proxy_pass http://192.168.50.4:9200;
        }

        return 403;
    }
carlalexander commented 6 years ago

Is that the code snippet that you used to get it working @yuriolive?

yuriolive commented 6 years ago

@carlalexander I got this code from the ElasticPress github directory, I didnt try to manually add in nginx conf file, I was waiting to see if have a alternative solution

carlalexander commented 6 years ago

No, let me try it out and see. But should be possible to add it 😄

robert1112 commented 6 years ago

Hi @carlalexander Any update on this? It's been a while now. Thank you so much.

carlalexander commented 6 years ago

I'm going to look into this after I fix the support for bionic beaver @robert1112

carlalexander commented 6 years ago

So I've been looking at the ElasticPress documentation. I'm assuming this isn't super well documented because 10up wants you to use their paid service. Whatever the reason might be, no one seems to be able to make it work. All the issues get closed and never fixed. I've tried and failed using their snippet and also tweaking the snippet as well.

On top of that, I'm also not super comfortable making an unsecured public endpoint. There's no documentation on how to secure elasticsearch to do this. I also assume 10up doesn't want to share this information either. But there's nothing out there that I could find to explain what to do about that.

I did manage to get autocomplete to work based off this stack exchange thread. Someone build a proof of concept plugin that created a REST API endpoint in WordPress for the autosuggest.

You already found this @robert1112. I left comment in the issue you opened. The main issue is that the plugin just uses a default index value of index. This isn't the name of the index that ElasticPress creates. You need to manually edit it to use the ep_get_index_name function or manually put your index name. You can find it by doing on your server:

$ curl -X GET "localhost:9200/_cat/indices?v"

For now, the best solution would be to use the mentioned plugin. (with the fix.) I would also consider pushing 10up to add an endpoint for autocomplete using the REST API. At this time, I don't feel this should be something that's configured on the server since I'm not sure about its security implications.