Download - Simple search with elastic search
![Page 1: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/1.jpg)
SIMPLE SEARCH WITHELASTIC SEARCH
MARK STORY@MARK_STORY
![Page 2: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/2.jpg)
WAT?Java basedLucene poweredJSON drivenDocument orientated databaseAll out super search solutionEasy to setup, and use
![Page 3: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/3.jpg)
INDEXES AND TYPESINDEXES
Similar concept to databases.Contain multiple types.
![Page 4: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/4.jpg)
TYPESSimilar concept to tables.Defines datatypes and indexing rules.
![Page 5: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/5.jpg)
DOCUMENT BASED REST APISimple to use and easy to understand.
![Page 6: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/6.jpg)
CREATE A DOCUMENTcurl -XPOST localhost:9200/contacts/people -d '{ "name": "Mark Story", "email": "[email protected]", "twitter": "@mark_story", "country": "Canada", "tags": ["cakephp", "cakefest", "canada"]}'
# Response:{"ok":true,"_index":"contacts","_type":"people","_id":"9izMCaSiQBqD1AJW8si57g","_version":1}
![Page 7: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/7.jpg)
READ IT BACKcurl -XGET localhost:9200/contacts/people/$id?pretty=true
# Response:{"_index":"contacts","_type":"people","_id":"9izMCaSiQBqD1AJW8si57g","_version":1,"exists":true,"_source" : { "name": "Mark Story", "email": "[email protected]", "twitter": "@mark_story", "country": "Canada", "tags": ["cakephp", "cakefest", "canada"]}}
![Page 8: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/8.jpg)
DELETE IT!curl -XDELETE localhost:9200/contacts/people/$id
# Response:{"ok":true,"found":true,"_index":"contacts","_type":"people","_id":"9izMCaSiQBqD1AJW8si57g","_version":2}
![Page 9: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/9.jpg)
SIMPLE SEARCH!More on search to come
curl -XGET localhost:9200/contacts/people/_search?q=Mark&pretty=true
![Page 10: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/10.jpg)
# Response:{"took":14,"timed_out":false,"_shards":{ "total":5, "successful":5, "failed":0},"hits":{ "total":1, "max_score":0.11744264, "hits":[ {"_index":"contacts", "_type":"people", "_id":"slJlyMBTSWaqAMfZUU-lDw", "_score":0.11744264, "_source" : { "name": "Mark Story", "email": "[email protected]", "twitter": "@mark_story", "country": "Canada", "tags": ["cakephp", "cakefest", "canada"] } } ]}}
![Page 11: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/11.jpg)
THIS ALL SOUNDS TOOBADASS TO BE TRUE
![Page 12: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/12.jpg)
DOCUMENT "DATABASE" IS ABIT LIMITED
Partial updates are doable but painfulNo joinsNo map reduceCannot replace all other datasources
![Page 13: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/13.jpg)
BUT SEARCH IS AMAZZZING
![Page 14: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/14.jpg)
SEARCH BETWEEN TYPES &INDEXESSearch multiple types
Search multiple indexes in your cluster
curl -XGET localhost:9200/contacts/people,companies/_search?q=name:Mark
curl -XGET localhost:9200/_all/people/_search?q=name:Mark
![Page 15: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/15.jpg)
FANCY SEARCH OPTIONS
![Page 16: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/16.jpg)
SEARCH WITH TEXTEXPRESSIONS
curl -XGET localhost:9200/contacts/people/_search?pretty=true -d '{ "query": { "query_string": { "query": "mark OR weldon" } }}'
![Page 17: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/17.jpg)
HIGHLIGHT SEARCHKEYWORDS
Wrap search terms in highlighting text/markup/html. Great for largerdocuments, as you can extract fragments.
![Page 18: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/18.jpg)
curl -XGET localhost:9200/contacts/people/_search?pretty=true -d '{ "query": { "text": { "email": "mark" } }, "highlight": { "fields": { "email": {}, "name": {} } }}'
![Page 19: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/19.jpg)
FACETSFacets provide aggregated data about a query. You can use this data
to create drill down search, or histogram data.
Term counts.Custom script values.Ranges - like price ranges.Geo distance facets - aggregate results by distance.
![Page 20: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/20.jpg)
curl -XGET localhost:9200/contacts/people/_search?pretty=true -d '{ "query": { "query_string": { "query": "*.com" } }, "facets": { "tagged": {"terms": {"field": "tags"} } }}'
![Page 21: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/21.jpg)
KNOBS & BUTTONS
![Page 22: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/22.jpg)
MAPPINGSAllows fine-grained searching later on, and lets you configurecustom mappings.Control the data types, and indexing used for JSON documenttypes.Disable indexing on specific fields.Configure custom analyzers. For example, non-english stemming.
![Page 23: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/23.jpg)
AVAILABLE MAPPING TYPESstring, integer, float, boolean, nullobject - Standard type for nested objects. AllowsArrays are automatically handled as the above.properties to be defined.
![Page 24: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/24.jpg)
multi_field - Allows a field to be handled multiple ways with differentaliases.nested - Indexes sub objects, and works with nested filter/queries.ip - For ipv4 data.geo_point - For lat/lon values. Enables piles of search options.attachment - Store a blob. Can index many text based documentslike PDF.
![Page 25: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/25.jpg)
CREATE A MAPPINGcurl -XPUT localhost:9200/contacts/people/_mapping -d '{ "people": { "properties": { "name": {"type": "string"}, "email": {"type": "string"}, "twitter": {"type": "string"}, "country": {"type": "string"}, "tags": {"type": "string"} } }}'
![Page 26: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/26.jpg)
DEFINE THE ANALYZER USEDWhen defining a field you can use analyzer index_analyzer,and search_analyzer to customize the way data is stored, and orsearched.You can also disable analyzing for specific fields.
![Page 27: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/27.jpg)
DISABLE INDEXING{ "name": { "type": "string", "index": "not_analyzed", }, "none": { "type": "integer", "index": "no" }}
![Page 28: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/28.jpg)
SHARDS & REPLICASSHARDS
Define how many nodes you want to split your data across.
If a node goes down, you still have some of your data.
You can use routing to control how data is sharded.
More shards improves indexing performance, as work is distributed.
![Page 29: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/29.jpg)
SIMPLE SHARDING
![Page 30: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/30.jpg)
SHARD OVER MULTIPLE NODES
![Page 31: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/31.jpg)
REPLICASDefine how many copies of your data you want.
If several nodes go down, you might still have all your data.
More replicas improves search performance and cluster availability.
![Page 32: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/32.jpg)
REPLICAS
![Page 33: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/33.jpg)
MULTI-TENANCYMulti-tenancy is a reasonably common requirement, and there are a
few ways to do it.
![Page 34: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/34.jpg)
ONE INDEX PER 'TENANT'
Great for small number of tenants.Painful for larger number of tenants. As sharding and replicas canbe harder to manage.
![Page 35: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/35.jpg)
curl -XGET localhost:9200/mark/contacts/_search?pretty=true -d '{ "query": { "query_string": { "query": "weldon OR jose" } }}'
![Page 36: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/36.jpg)
SPECIAL FILTER CONDITIONS
More error prone as you have to include a filter condition.Easy to shard and setup replicas.Easily scales to many tenants. As shards/replicas are shared.Make sure tenant id is a non-analyzed value.
![Page 37: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/37.jpg)
curl -XGET localhost:9200/accounting/invoices/_search?pretty=true -d '{ "query": { "filtered": { "filter": { "term": {"accountid": 1} }, "query": { "query_string": { "query": "purple wifi" } } } }}'
![Page 38: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/38.jpg)
OTHER BATTERIES INCLUDEDRouting Define how documents are sharded.
Rivers Pipe data in realtime from sources like RabbitMQ.
Thrift Talk thirft to ElasticSearch.
![Page 39: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/39.jpg)
INTEGRATION WITHCAKEPHP
![Page 40: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/40.jpg)
HTTPSOCKET + JSON_ENCODE()Basic, can be hard to use.No magic.
![Page 41: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/41.jpg)
ELASTICSEARCH DATASOURCE
Behavior to auto index on aftersaveDatasource for searching elasticsearchConsole app to index models
(David Kullman)
![Page 42: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/42.jpg)
ELASTICSEARCH PLUGIN
Similar features to the previous pluginOffers more control on how data is indexed
(Kevin von Zonneveld)
![Page 43: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/43.jpg)
QUESTIONS?
![Page 44: Simple search with elastic search](https://reader034.vdocument.in/reader034/viewer/2022052315/555df1f1d8b42a3f618b47ee/html5/thumbnails/44.jpg)