 Hey everybody, welcome to modernizing WordPress search with Elasticsearch. So as Sarah said, my name is Taylor Lovett. I'm the director of Web Engineering at TenUp. I'm an open source community member, a WordPress core contributor, and an Elasticsearch team member. So doesn't WordPress have search build-in? That's the big question. WordPress search is pretty simple, and anyone who runs a WordPress website should know that. By default, WordPress only searches the post title, post content, and excerpt. It relies on MySQL, as we all know, which can be slow in certain situations. Search results and relevancy calculations are pretty simplistic and aren't able to handle a lot of customization. And there isn't really a way to do any sort of advanced filtering. So I know this talk is filled with the word search, but I want everyone to think beyond search when they're listening to me and coming out of this talk. WordPress complex queries in general can be very slow. And by complex queries, I'm talking about multidimensional meta queries and multidimensional taxonomy queries, and we're going to get into a little bit of what exactly that means if anybody doesn't know as the talk progresses. So what is Elasticsearch? Elasticsearch is open-source software. It's written in Java. It is based on a technology called Lucene, which is put out by the Apache Foundation. It is a standalone database server. It has a restful interface. I know we've talked a lot about rest today. So it can accept and store data just like any sort of other storage mechanism can. I guess really the takeaway is it's a standalone database server that is separate from MySQL. It's extremely scalable, performant, and reliable, and it makes doing some of these complex queries and search things much easier. So with Elasticsearch, we can do a lot of cool stuff, and this is just a small list. We can handle relevancy with results. We can do performant aggregation queries. We can do things like auto suggest where you type in the input box and it's able to instantly suggest things to you like similar to what Google does. We can do fuzzy matching. So we can handle things like misspellings in search if somebody swaps two letters or something like that. We can actually do geographic search, which is very amazing. In general, we can do filterable searches and queries much more performantly. We can wait data. So there's a ton of really used applications for Elasticsearch or WordPress. So step one for getting this going on your website or on my client's website or maybe just playing around with it locally is you need an Elasticsearch server. You basically have two options. You can go through one of the many SaaS providers, or you can host your own cluster. If you're doing this locally, it's super easy to spin up Java and Elasticsearch. It takes like five minutes to install. I just do it within my vagrant machine. Here's a list of some of the Elasticsearch SaaS products. Elasticpress.io, that's 10 UPS Elasticsearch SaaS product and that's secured for enterprise. Qbox.io is a great one. They're relatively affordable. Heroku has one. Amazon pretty much every major cloud-based infrastructure company offers some sort of Elasticsearch SaaS product at this point. OK, so what is Elasticpress? Well, Elasticpress is a 10-up WordPress plugin that creates a framework that allows for the dramatic improving of WordPress performance and search. And remember at the beginning of the talk, I talked about how I want everyone to think about going beyond search and the performance implications of Elasticsearch and Elasticpress. So remember. So Elasticpress lets us do a lot of really cool things with WordPress. The main things are it lets us do filterable performance queries. Again, letting us filter by meta, filter by taxonomy terms, all sorts of things. It lets us do fuzzy searching of the post title, the content, excerpt, taxonomy terms with Elasticpress and Elasticsearch. You can fuzzy search anything in your database. It lets us search across blogs in a multi-site instance, which is very powerful. And if anyone's ever tried to do that, it's not very easy. And it's very hacky without something like this. We can search results and get results returned by relevancy. And those relevancy calculations are very customizable. Elasticpress, one of the cool things we can do with that is wait results by recency. So I can't tell you how many times I've worked with a client that they've typed in something in their search results and gotten a result from like 2010 when they posted something yesterday that was very similar and they're just like, why, you know, this doesn't make any sense. Why would I get something from 2010? So we can wait results by recency. And it is also very extensible, lots of actions and filters, and it's very performant. So Elasticpress requires at least WordPress 3.7 and obviously an instance of Elasticsearch. Installation of Elasticpress itself is very simple. You can clone it off GitHub, you can grab it off the WordPress.org plugins repository. Once you have Elasticsearch set up, it's quite simple and I'm going to run you through the steps. So once you've activated the Elasticsearch plugin in your WordPress dashboard, you get to this sort of setting screen. The first thing you're going to want to do is put in your Elasticsearch host. So maybe that's like an IP address or something with the port. That's just where Elasticsearch is. You plug it in, you save it. Elasticpress keeps Elasticsearch in sync with your content. So that's kind of the fundamental piece of how the whole thing works. So before you can do anything, you have to sync your content to Elasticsearch. So you can run an index and it'll do that all asynchronously and you can leave the page and come back and not have to worry about it. So once our content is synced, we have our Elasticsearch host set up properly. At that point, we have access to all the really cool Elasticsearch functionality and the inner API of Elasticsearch. At this point, we can tell Elasticsearch to run all of our search queries through Elasticsearch instead of MySQL. And to do that, you just check that simple box. So what happens next? Well, once you have all your content synced and everything is indexed and everything, Elasticpress is going to hook into the WPQuery object and it's going to run your queries against Elasticsearch instead of MySQL. So the bulk of what Elasticpress is really doing is hooking into WPQuery to parse the arguments that are passed to that object and it's going to format all that stuff up into the Elasticsearch query DSL, which is how Elasticsearch understands stuff. It's going to send that over to Elasticsearch and then it's going to take the results back and put them back into the query behind the scenes. So from a developer's perspective, it all works pretty much the same. It's just routing it through Elasticsearch and sending it back. One of the most important things to understand is Elasticpress is only going to integrate with your query if a special parameter EP integrate is passed to the query, so you don't have to worry about activating Elasticpress and now all of a sudden it breaks your entire website. It listens for that special parameter. And then, of course, if you have the search integration enabled, it's going to also look for that S parameter so it's going to integrate with your search queries. Let's look at some example code. The first two queries highlighted in green, those queries are going to be integrated with Elasticpress. The first one, because of that S parameter, it's a search query, so Elasticpress knows that it should retrieve that information from Elasticsearch. The second one, we're using our special EP integrate parameter, so again, Elasticpress knows where to get that data from. The third one, just a normal query. Nothing's going to change. It's just going to go through MySQL. So with Elasticpress, we can do a lot of really powerful advanced queries. We can search taxonomy terms. By the way, searching taxonomy terms, how many times have you guys had a client that has wanted to search their categories and search their tags when they go to search their website? I've experienced that many times and it's not very easy to accomplish. So searching taxonomy terms, post-meta, filtering by those things, we can actually search authors and filter by authors. Again, we can search across blogs in a multi-site. A lot of really, really powerful functionality. So I'm just going to run through a couple example queries. Like I said, Elasticpress integrates with WP query and accepts pretty much all the same parameters that it does, but it has a couple special ones. So this site parameter, sites parameter, if we pass it to WP query, it's actually going to query all the blogs in our network. Another special parameter, search fields. This lets us actually choose which field should be searched. So in this case, it's going to search post title, post content, and the category taxonomy. Again, another search. This time, we're actually filtering by author, we're filtering by post type, and we're specifying the search fields post title, post content, and then the meta key city name. So it's actually going to search that meta key for us. Again, all this stuff is very performant, results return pretty much instantly. Another more advanced query, we're searching a bunch of fields. Again, we're searching a meta key. We're actually searching an author name, which is pretty cool. And then after that, we're filtering with a tax query. We're filtering by categories that have that term one and term two. And then at the very end, kind of hiding, we're only getting data from the blog with the ID of three. So here's another query. This one isn't a search query, but we're passing that EP integrate true, and we're doing a three-dimensional taxonomy query. So I've talked about the performance implications of elastic press. Doing a three-dimensional taxonomy query in WordPress right now is very, very slow. Obviously, that depends on the size of your terms table and all those tables. But doing a three-dimensional query in a production website that perceives a lot of traffic is just pretty dangerous. And with elastic press, we can accomplish those things very, very performantly. Same thing here. We're doing a three-dimensional meta query. We're using the EP integrate parameter to tell elastic press what to do. And I'm just showing three dimensions for the size of the screen, but we could go up to as many dimensions as we want and make these queries as crazy as we want. And all that is going to happen performally. So the goal of the project is we want to be able to run all slower WP query instances and search instances through elastic search. This means we have to support every single argument that WP query supports, which is quite the task. Some of the arguments don't make sense. Some of them aren't even possible, given the code that's in core. So I would encourage you to check GitHub for a full list of the WP query parameters that we can actually support. Another really cool thing with elastic press is we have modules. We want to speed up all things WordPress. And this includes plugins. So two of our models right now, we have elastic press with commerce. So this is a great one. If you have thinking about an e-commerce query where you want to find products that are either blue or red and greater than a certain price, and in this category, in that category, doing those types of queries with WordPress, it just isn't really possible right now. So elastic press lets you do those things and makes them fast. We can also find related posts in a really cool fashion using elastic search as relevancy calculations. So those are some really cool models. Anyone in the community is encouraged to build their own and tell us about them. And more will, of course, be coming soon. I know I'm running out of time here. Elastic press is designed to be internationalized out of the box. It works fine with most languages. Basically, when a document is indexed, it's tokenized and broken into terms. Porels are stripped out and prefixes are handled in a specific way. And all that by default is done in an English manner, which works fine, again, for most languages. But certain languages, you'll be better off specifying your own analyzer. And analyzers are available in most major languages at this point. So to do that with elastic press, all you have to do is filter EP config mapping. And you can tweak it to use whatever languages you want. And I have a documentation link. Again, full documentation with installation instructions. It's all on GitHub. If anyone here is using elastic press on a project, please let us know and give us feedback. We're hoping to improve it and make it as big as possible. Of course, pull requests are always welcome. And that's all I have.