Elasticsearch + Rails: How to set up an awesome search box in your app

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this talk I'm going to implement a pretty neat search for using elastic surgeons out to integrated with your rails app so before that a little bit of background about beat as Amiga said I'm one of the co-founders at ample market I think he didn't be explain what we do but your YC back company pretty small we build a virtual sales assistant I'm also part of the team M philmont's library she's something really different but it's an addition platform for academic papers until we we've used the elastic search quite a lot you're at ample market and it has worked great for us and that that is part of the reason why I decided to get the stock the other reason is that I think that a lot of websites do search they just have crappy search bars and be and I was thinking about it and I don't think I really trusts many search far to the side schools I'm Amazon I'm at a random media website I'm not going to use the search for teach and so as an example I went to five o'clock which is a fairly big online retailer here in Portugal and I searched for you MacBooks but with the specific ipod missing the a and you just get no results and so this is this is bad right this is a bad user experience and they are using money and if you go to Amazon and you do the same query they know that you're searching for a MacBook they search you to show you the right results and they even have a neat neat filters your on the side that and allow you to further drill down in your search so so the goal should be to build a great user search experience that users can trust and be they can rely on your search bar and the elastic search is a great tool that can help do that and so but the the before I go into elastic search it's a fair questions and answers why can't I just use my c4 or Postgres for folks that's might that might be the data store though you're using out dates and my point here is not that the last thing search is always the answer right you can definitely do a lot with just post press or my people my point is that as your search requirements get more complex if you do that as you need to support say different languages or synonyms or faceted search or typos that's when you maybe want to start thinking about adding elastic search and for a long time here at implement we tried to employ adding less searches because it was an intra dependency and we already knew how to choose pretty good just rely on it but then eventually we decided to add traffic certain death as a mean of course removing your mainly the source post presence or main data source but to use elastic search quite ever we now into a little bit of background into elastic search it's an open source search engine written in Java and it was built on top of the party we've seen which is an indexing library and it was released in 2010 and the company but behind the last search last which is called elastic IPO the the other IPO earlier this year and today I'd check them they're worth four point eight billion dollars so it's a pretty big company you don't need to know Java in order to use it you can just interact with it via an HTTP interface and it's a document-oriented database right so similar to MongoDB that would be versus a relation relational database like post for Eliza and it has been and this is not just a start up product as I said it's a massive company it's used by very mature companies so it's been battle tested in production environments so you can trust that it's not going to go away anytime soon like that bomb so so it's if you are if you're using a Mac it's real easy to install just blue install elasticsearch then you started and then it usually listens to port 9200 to distinct or local laws 9200 you get a reply back from the last search saying everything is good so it's very easy to get set up and lasting search is distributed so it's distributed as edit score but at the same time as you can see it's very easy to sit to get it going your development apart a few concepts that you want to know if you're going into elasticsearch there's yeah indexes need to see it and the index is very different from what an index in index and elasticsearch is very different from what it is in Postgres for my sequel an index is basically a namespace where you where you store data and then as I said it's document-oriented database and so you store lady in two documents and those are basically Jason not objects and the equivalent concepts for relational databases would be primitive just database for the document it's row so there are a lot of ways of integrating elasticsearch with your rails app I like to use a gem called circuit which is developed by instacart and that's a company in San Francisco they do grocery believers they use rails and they're very large company in the US and it's very easy to integrate with your real self I'll show you I'm gonna have a demo so I'll show you later but just add it to your gem file add it to the models but do you want to search through then you want to send that data that you have in your main store main data store to elasticsearch you can do that by model the index and then you're good to go let's start using it for search so so now we're going to do that where we're basically we're going to integrate it with a with a small and so this is an app that has a data set of about 20,000 movies into it as the title release here on genre the movie director gasps and fought and so this we're going to try and go through and this is the this is the app right here can you see your right and so we're gonna try and integrate elasticsearch with this rails app and implement basically implement this search here and so bear with me I've never been to meet up with a demo that didn't go something didn't go wrong so we might uh let's see how this goes but so as I said first thing you want to do is edit to your gem file right so alright now we want to add that search kick to our model to our movie model so we're going to be searching so that's done so now this is the end point that is getting hit here and right now as I said this this search is just that didn't take too long right yeah it's also really weird to type on my podium ok yeah so we're just going to implement this so that the input that is getting it is the indexed end point so we're going to want to store the query in the class variable yeah um so you want to write the search the search box is gonna take in anything and you want to want to start it then if we have and here we're gonna pass the fields that we want lassus elasticsearch to search through so we were going to start by when it searched through the title director cast plot alright looks good here there's somebody from a lasting here so if I'm doing something wrong feel free alright strength okay so see so that was easy this is a very basic search but um so it's returning Star Wars movies we can see that I'm right is it searching all those fields so we have we can see that the third hit is this murder in the in the air it's matching saying you're right start worse at the bottom there and so so that's kind of weird too maybe we want to give more weight to the title and and so that's really easy to do in elasticsearch it's called boosting and so the syntax for that here would be like this you just do half and then a number and I will just I boost the let score there so if we if we search again hopefully we'll see that that's not the third date and yeah alright so so this is a pretty basic search another thing that I'm gonna implement here will be the search ever be able to filter by by decade here and so I already implemented some of the the front end logic send the decade so we want to fetch select the decades is going to be it's coming so so this is right it's just gonna be selected to selected that that gives you just going to be an array but as the decades that we selected and it's coming as they're coming in string so we want to map them to an integer because they are the the the release decade of the movie stored in the database as an integer and now we're gonna use the where clause and that is going to be so yeah so it should be right to it um does easy as this so in elasticsearch you can just you could just pass in a where clause like this so this is a little bit you just passing it you can pass in a query which is just a string and then it will search through the fields that we pass in and this is a where clause that or we're going to select movies from decades or we selected in that in the front so let's make sure when it's the working it's a little bit slower but I think it's more because I'm running screen capture and everything I'm not really present elasticsearch so let's try and do this in clear and then let's Street then to the sixties right so we can see so I'm showing us movies from the 60s now what a lastly what I'm going to try and implement is its aggregations so Amazon also does this where you search for a product and then it shows you up for all the different categories how many matches their work for each category so here we would like to see how many movies for each decade have the nuclear keyword for instance and so so for that for that we're going to use a feature of elastic search that is called aggregations and so so we're going to aggregate but the and yeah yeah previously I did the logic and this this here on the right but I did some comment is just a logic to you for the numbers to show up and just did that beforehand so so this is an aggregation exit this is an aggregation for nuclear and we can see that speaks you're in the in the 80s at the end of the Cold War so I guess it did a lot of nuclear movies back then but so you can see how easy it was to do aggregation is there so this is just the tip of the iceberg this is this is a fairly basic search but you can see like took less than five minutes to do this but you can really do a lot with elastic search and and because the way that it's really developer friendly and so that as I was saying it's it's it's distributed at its core so you can scale really well at the same time it's really easy to get to speed and deploying it on a Roku it's really really easy and so it can really help you build a great search experience so it applies if you have to need for a good search bar when your website to really look into it yeah that's all
Info
Channel: amplemarket
Views: 1,767
Rating: undefined out of 5
Keywords: elastic, elasticsearch, rails, ruby on rails, ror, search, amplemarket, sales assistant, sales, sales automation
Id: BDSa_tCfjNg
Channel Id: undefined
Length: 16min 58sec (1018 seconds)
Published: Sun Jan 06 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.