Ask A Question

Notifications

You’re not receiving notifications from this thread.

Advanced Search, Autocomplete and Suggestions with ElasticSearch and the Searchkick gem Discussion

Chris, this is awesome!

I was hoping you'd do a Searchkick/ElasticSearch video since you did the Ransack video!

Thanks for all the great videos!

Reply

Thanks Nick! :)

Reply

Great video!

Reply

Thanks Chris – another great tutorial!

What about if you want to search through more than 1 items, with a separate MVC.
Say you have Questions and Answers. I tried modifying the search form but it seems
there are lot more areas to look at.

Reply

can you share your experience , searching multiple models in one query please , i can't get it to work

Reply

Thanks for your this great video @excid3:disqus . I advise people to use Algolia if they want to use a database search https://blog.algolia.com/fu...

Reply

can we please have the github link?

Reply

Hello Chris....
If I have many models and I want a common search that works for all the models and gives results from all models in common search result page then how is this possible?

Reply

You'll either need to do separate searches and combine the results or index one main model and include the nested models attributes in the index.

Reply

Thanks for the tutorial. I tried to install elasticsearch but i get an error. I explained the full error in this post http://goo.gl/cqVFyl in stackoverflow.

Reply

Hello Chris, I included elastic-search as you explained in the tutorial... working perfectly on local... but when I put on digitalocean server, they blocked my droplet that network is not secure with process of elastic search and If I get it stop and secure it then will open... How I can secure the elastic search for production server?

Reply

You might check this out: http://brudtkuhl.com/securi...

Reply

I have just finished the One Month class on RAILS and checked into this. (which is obviously a bit more advanced). How does one generate a Questions controller or does that arrive when you bundle instal the search gem?

Reply

You can generate a scaffold for it just like you did with the posts in the Rails class. You'll possibly want different fields, but you can create it the same way.

Reply

Is anyone else having this problem? http://stackoverflow.com/qu...

I've been trying to install elastic search but ran into some issues with homebrew and java. I recently upgraded to Yosemti and it seems to be the issue. Anyone know of a fix

Reply

Any thoughts on how to highlight results?

Reply

I am trying to follow along with this but I get this error when I try Article.reindex (equivalent of Question.reindex)

NoMethodError: undefined method `reindex'

In the console, I try: Article.reindex

It returns:
NoMethodError: undefined method `reindex' for Article (call 'Article.connection' to establish a connection):Class

Also, when I try to run the local host, I get this error:

Index missing - run Article.reindex
# GET /articles.json
def index
@articles = Article.search(params[:q])
end

# GET /articles/1

For me:

def index
query = params[:q].presence || "*"
@articles = Article.search(query)
end

gives this error:

MissingIndexError in ArticlesController#index
Index missing - run Article.reindex

My key difference is that:

I use simple form for forms, so i made a new partial to insert in my articles index as:

<%= simple_form_for(@article) do |f| %>

<%=f.text :q, :nil, placeholder: "Search" %>

<% end %>

TOTAL NUMPTY: I DIDN'T INSTALL THE GEM. SORRY!

Reply

Thanks for the awesome video! Switched from sphinx to elasticsearch. Much easier!

Reply

How would I search a Post model where I wanted only see published post? Can't figure out how the code should look in the controller index.

Reply

You can actually just add that into your query. For example, if your published column was a boolean: Post.search('*',where:{published:true})

Reply

And just like that, all my troubles disappear. Thanks man!

Reply

How can I add 'will paginate' to the search results... in class PostsController < ApplicationController?
I currently have this;

if query = params[:post_search].presence || "*"
@posts = Post.search(query, suggest: true)

Reply

Finally this works:
@posts = Post.search(query, page: params[:page], per_page: 10)

Reply

Thanks for the video Chris. I am having issues with the autocomplete part. I have jquery-ui loaded and everything done up to the point where I try to test the libraries are loading (up to 17:32mins into the video. My first autocomplete test does not show anything (was expecting the word TEST would show as in your case). When I inspect the element, I see the following error:

Failed to load resource: the server responded with a status of 404 (Not Found) - https://bakr-fgneba.c9users...
When i click on the link i see the error (Couldn't find Post with 'id'=autocomplete). Looks like something to do with routing.

My route is defined as:

resources :posts do
get :autocomplete
end

Any idea why this could be happening?

Reply
Josh Zandman Josh Zandman

Hi Chris, i've tried using Bonsai and SearchBox for deploying to Heroku and both are a nightmare to get working. Do you have any recommendations on deploying to Heroku?

Reply

It should just pick up the searchbox ENV variable and work. Depending on how many models you're indexing, you'll need the correct number of shards available (some of the ES options limit shards or other things).

Reply

Hi Chris!

I love the videos! I've been stuck on this problem for a while and tried StackOverflow(http://stackoverflow.com/qu... but with no response and I know you're busy but I thought I'd try.

I have forums(the parent model) that have many forum_threads but each forum_thread is unique to that certain forum. I'd like to be able to search each forum (which IS working just fine) as well as each forum_thread within that unique forum(which is just rendering ALL forum_threads rather than the searched thread). Would you be so kind as to take a look at my SO question and see what I'm doing wrong?

Reply

Has anyone else had a problem with search_data like this: https://gorails.com/forum/s... ?

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,969+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.