modernizing wordpress search with elasticsearch

39
Modernizing WordPress Search with Elasticsearch

Upload: taylor-lovett

Post on 16-Feb-2017

271 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Modernizing WordPress Search with Elasticsearch

Modernizing WordPress Search with Elasticsearch

Page 2: Modernizing WordPress Search with Elasticsearch

Who Am I?

• My name is Taylor Lovett

• Director of Web Engineering at 10up

• Open source community member

• WordPress core contributor

• ElasticPress team member

@tlovett12

Page 3: Modernizing WordPress Search with Elasticsearch

Doesn’t WordPress have search built-in?

Page 4: Modernizing WordPress Search with Elasticsearch

WordPress Search is Rudimentary

• Only searches post title, content, and excerpt.

• Relies on MySQL and thus is slow.

• Relevancy calculations are poor and overly simplistic.

• Not able to handle any advanced filtering.

Page 5: Modernizing WordPress Search with Elasticsearch

Think Beyond Search

Page 6: Modernizing WordPress Search with Elasticsearch

WordPress Complex Queries Are Slow

• Querying for posts that contain multiple meta keys.

• Querying for posts that contain multiple taxonomies.

Page 7: Modernizing WordPress Search with Elasticsearch

What is Elasticsearch?

http://www.elastic.co

Page 8: Modernizing WordPress Search with Elasticsearch

Elasticsearch• Open-source search server written in Java

based on a technology called Lucene (open-source search software by Apache).

• A standalone database server that provides a RESTful interface to accept and store data in a way that is optimized for search and multi-dimensional queries.

• Extremely scalable, performant, and reliable

Page 9: Modernizing WordPress Search with Elasticsearch

Elasticsearch• Relevant results

• Performant aggregation queries

• Autosuggest

• Fuzzy matching

• Geographic searches and queries

• Filterable searches and queries

• Data weighting

• Much more

Page 10: Modernizing WordPress Search with Elasticsearch

Get an Elasticsearch Server

• Very flexible and customizable. There is not really a “one size fits all” setup. Generally, you have two options:

• Option 1: Pay someone else to manage/host your Elasticsearch cluster (SaaS)

• Option 2: Host your own cluster

Page 11: Modernizing WordPress Search with Elasticsearch

Elasticsearch SaaS

• elasticpress.io

• qbox.io

• heroku.com

• etc…

Page 12: Modernizing WordPress Search with Elasticsearch

What is ElasticPress?

https://wordpress.org/plugins/elasticpress

Page 13: Modernizing WordPress Search with Elasticsearch

ElasticPress

A free 10up WordPress plugin that creates a framework for dramatically improving WordPress performance and search.

Page 14: Modernizing WordPress Search with Elasticsearch

ElasticPress• Build filterable performant queries (filter by taxonomy

term, post meta key, etc.).

• Fuzzy search post title, content, excerpt, taxonomy terms, post meta, and authors.

• Search across multiple blogs in a multisite instance.

• Search results returned by relevancy. Relevancy calculations are highly customizable. Weight results by date.

• Very extensible and performant.

Page 15: Modernizing WordPress Search with Elasticsearch

ElasticPress Requirements

• WordPress 3.7+

• An instance of Elasticsearch.

Page 16: Modernizing WordPress Search with Elasticsearch

Installation

• Github: http://github.com/10up/elasticpress

• WordPress.org: http://wordpress.org/plugins/elasticpress

Page 17: Modernizing WordPress Search with Elasticsearch

Point to Your ES Instance

Page 18: Modernizing WordPress Search with Elasticsearch

Sync Your Content

• Just activating the plugin will do nothing. We need to sync (index) our content.

Page 19: Modernizing WordPress Search with Elasticsearch

Sync Your Content

Page 20: Modernizing WordPress Search with Elasticsearch

Integrate with Search

• Now that our content is synced, we have access to all the powerful ElasticPress functionality i.e. query content through ElasticPress and install ElasticPress modules (WooCommerce).

• We need to tell ElasticPress to run all our search queries through Elasticsearch

Page 21: Modernizing WordPress Search with Elasticsearch

Integrate with Search

Page 22: Modernizing WordPress Search with Elasticsearch

What Happens Next?

• Once ElasticPress is activated and posts are indexed, it will integrate with WP_Query to run queries against Elasticsearch instead of MySQL.

• WP_Query integration will only happen on search queries (if “Elasticsearch integration” is enabled) or when the ep_integrate parameter is passed.

Page 23: Modernizing WordPress Search with Elasticsearch

Query Integrationnew WP_Query( array( ’s’ => ‘search terms’, ‘author_name’ => ‘taylor’, …) );

new WP_Query( array( ’ep_integrate’ => ‘true’, ‘author_name’ => ‘taylor’, …) );

new WP_Query( array( ‘author_name’ => ‘taylor’, …) );

Page 24: Modernizing WordPress Search with Elasticsearch

Advanced Queries• Search taxonomy terms

• Filter by taxonomy terms (unlimited dimensions)

• Search post meta

• Filter by post meta (unlimited dimensions)

• Search authors

• Filter by authors

• Search across blogs in multisite

• Complex date filtering

• more!

Page 25: Modernizing WordPress Search with Elasticsearch

Example Queries

new WP_Query( array( ’s’ => ‘vienna austria’, ‘sites’ => ‘all’,) );

Page 26: Modernizing WordPress Search with Elasticsearch

Example Queries

new WP_Query( array( ’s’ => ‘vienna austria’, ‘search_fields’ => array( ‘post_title’, ‘post_content’, ‘taxonomies’ => array( ‘category’ ), ),) );

Page 27: Modernizing WordPress Search with Elasticsearch

Example Queriesnew WP_Query( array( ’s’ => ‘vienna austria’, ‘post_type’ => ‘page’, ‘author_name’ => ‘taylor’, ‘search_fields’ => array( ‘post_title’, ‘post_content’, ‘meta’ => array( ‘city_name’ ), ),) );

Page 28: Modernizing WordPress Search with Elasticsearch

Example Queriesnew WP_Query( array( ’s’ => ‘vienna austria’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘category’, ‘terms’ => array( ‘term1’, ‘term2’ ), ), ), ‘search_fields’ => array( ‘post_title’, ‘post_content’, ‘meta’ => array( ‘city_name’ ), ‘author_name’, ), ‘site’ => 3,) );

Page 29: Modernizing WordPress Search with Elasticsearch

Example Queriesnew WP_Query( array( ‘tax_query’ => array( array( ‘taxonomy’ => ‘category’, ‘terms’ => array( ‘term1’, ‘term2’ ), ‘operator’ => ‘or’, ), array( ‘taxonomy’ => ‘custom_tax’, ‘terms’ => array( ‘customterm1’ ), ), array( ‘taxonomy’ => ‘post_tag’, ‘terms’ => array( ‘tag1’ ), ), ‘relation’ => ‘OR’, ),) );

Page 30: Modernizing WordPress Search with Elasticsearch

Example Queriesnew WP_Query( array( ‘meta_query’ => array( array( ‘key’ => ‘city_name’, ‘value’ => ‘vienna’, ), array( ‘key’ => ‘number_key’, ‘value’ => 5, ‘compare’ => ‘>’, ), array( ‘key’ => ‘exists_key’, ‘compare’ => ‘exists’, ), ),) );

Page 31: Modernizing WordPress Search with Elasticsearch

WP_Query Integration

• We want to be able to run all (slower) WP_Query instances through Elasticsearch.

• This means we have to support every query parameter which isn’t the case yet. Github contains a full list of parameters WP_Query supports with ElasticPress and usage for each parameter.

Page 32: Modernizing WordPress Search with Elasticsearch

ElasticPress Modules

• We want to speed up all things WordPress. This includes third party plugins too.

Page 33: Modernizing WordPress Search with Elasticsearch

ElasticPress Modules

• ElasticPress WooCommercehttp://wordpress.org/plugins/elasticpress-woocommerce

• ElasticPress Related Postshttps://github.com/10up/ElasticPress-Related-Posts

• More coming soon.

Page 34: Modernizing WordPress Search with Elasticsearch

ElasticPress in Your Language

• ElasticPress is designed to be internationalized.

• Out of the box, it will work fine with most languages.

Page 35: Modernizing WordPress Search with Elasticsearch

Analysis and Analyzers

• When a document is indexed in Elasticsearch, text is analyzed, broken into terms (tokenized), and normalized with token filters.

• In normalization, strings might be lowercased and plurals stripped.

Page 36: Modernizing WordPress Search with Elasticsearch

Custom Analyzers• ElasticPress by default uses a pretty standard set of

analyzers intended for the English language.

• We can easily customize our analyzers for use with other languages by filtering ep_config_mapping (see EP source code).

• You can read about language specific analyzers here:http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/analysis-lang-analyzer.html

Page 37: Modernizing WordPress Search with Elasticsearch

Documentation

Full documentation with installation instructions:

https://github.com/10up/ElasticPress

Page 38: Modernizing WordPress Search with Elasticsearch

Feedback and Continuing Development

• If you are using ElasticPress on a project, please let us know and give us feedback.

• Pull requests are welcome!

Page 39: Modernizing WordPress Search with Elasticsearch

Questions?

We need to send a PUT request to this endpoint with our post data. Of course we must authenticate before

doing this.

@tlovett12

[email protected]