What Is Elasticsearch? • Storage Engine • Schema Free • Document Oriented • Built on top of Lucene • Opensource • RESTFul (JSON over HTTP) • Multi-tenancy Saturday, June 30, 12
Indexes & Types • Index: Group of Items (Types) • Types: Relevant Data in a Group • Amazon: Books, Movies, Clothes, Etc. • Airlines: American, Delta, KLM, etc. • Each Type & Index can have different data elements Saturday, June 30, 12
PUT vs POST POST {"ok":true,"_index":"dfw","_type":"brewery ","_id":"Iw9kfa3vSx2FyFen- uK26Q","_version":1} POST OR PUT {"ok":true,"_index":"dfw","_type":"brewery ","_id":"1","_version":1} PUT No handler found for uri [/dfw/brewery/] and method [PUT] Saturday, June 30, 12
Elasticsearch API’s • Allow you to perform operations • Search, Add Mappings, Status, Refresh & Optimization • It’s just another endpoint • Checkout Elasticsearch.org for lots more Saturday, June 30, 12
Status • Displays Comprehensive Status Information on an indices. • Can be done at all levels (es, index, type) • Endpoint: _status Saturday, June 30, 12
Refresh & Optimize • Refresh: refresh data for near real-time search. • All Levels • Endpoint: _refresh • Optimize: Optimizes Lucene segments for faster searching. • All Levels • Endpoint: _optimize Saturday, June 30, 12
Mapping • Defines how the document is mapped to search engine • You don’t have to define this. It’s dynamic. But you can.... • You can define them at the Index and Type level • Endpoint: _mapping Saturday, June 30, 12
What you can Define • What fields are searchable • Fields dataType • How they are stored • How they are tokenized (index, analyzed) • etc... Saturday, June 30, 12
Delete Mapping curl -XDELETE 'http://localhost:9200/dfw/brewery/ _mapping' Important to note that you are just deleting the mapping not the data. Saturday, June 30, 12
URI Request • Performed through a web request or curl request. • Simple & Limited • No Filter, Facet, etc. http://localhost:9200/dfw/brewery/ _search/?name:Deep Ellum Brewing Company Saturday, June 30, 12
Faceted Searching • Facets are “Logical Groupings” that allow easier search navigation. • Drill down searching • Think Amazon or NewEgg.com • Type of Facets in Elasticsearch • Terms, Range, Histogram, Date Histogram, Statistical, & Geo Saturday, June 30, 12
Other Features • Highlighting • TTL • Routing - Tell were to look at node/shard, etc. • Scripting • Scrolling - Pagination of results • Plugins - Rivers & Attachments Saturday, June 30, 12
Elastica • PHP Library • Opensource Project • GitHub - https://github.com/ruflin/Elastica • Follows ZF Standards • Alternative to cUrl • Not a lot of documentation but there are TESTS! Saturday, June 30, 12
Elastica • Everything is an Object • Inject objects to create Queries. • Under the hood - Array Based converted to JSON. • Debug • echo json_encode($query->toArray()) Saturday, June 30, 12
Examples • ElasticSearch Query DSL vs. Elastica • Preloaded Index (dfw) with two types (brewery, beer). • Uses BreweryDB data through the API • Examples available on Github Saturday, June 30, 12