Drupal And ElasticsearchAlex Goja
Flexible and powerful open source,
distributed real-time search and
analytics engine for the cloud
Elasticsearch
Flexible and powerful open source,
distributed real-time search and
analytics engine for the cloud
Elasticsearch
RESTful API on top of Lucene library
Why use
Elasticsearch?
Why use
Elasticsearch?
● RESTful API 

● Open Source 

● JSON over HTTP 

● based on Lucene 

● distributed 

● highly available 

● schema free 

● massively scalable 

How to use it?
How to use it?
> curl -XGET localhost:9200/?pretty
How to use it?
> curl -XGET localhost:9200/?pretty
{

"ok" : true,
"status" : 200, "name" : "Infinity",
"version" : {
"number" : "0.90.1",
"snapshot_build" : false,
"lucene_version" : "4.3"
},
"tagline" : "You Know, for Search"
}
How to use it?
> curl -XGET localhost:9200/?pretty
action
How to use it?
> curl -XGET localhost:9200/?pretty
node + port
How to use it?
> curl -XGET localhost:9200/?pretty
path
How to use it?
> curl -XGET localhost:9200/?pretty
query string
Let's index some data
Let's index some data
> PUT /index/type/id
Where?
It's very similar to database in SQL
Let's index some data
> PUT /index/type/id
What?
Table

Content type,

Entity type,

any kind of type you decide
Let's index some data
> PUT /index/type/id
Which?
Node ID, Entity ID,

any kind of serial ID
Let's index some data
> PUT /mysite/node/1
{

"nid": "1",
"status": "1",

"title": "Hello elasticsearch",

"body": "First elasticsearch document"
}
Let's index some data
> PUT /mysite/node/1 -d
{
"nid": "1",
"status": "1",

"title": "Hello elasticsearch",

"body": "First elasticsearch document"
}
{

"ok":true,
"_index":"mysite",
"_type":"node",
"_id":"1",
"_version":1
}
Let's GET some data
Let's GET some data
> GET /mysite/node/1
{

"_index" : "mysite",
"_type" : "node",
"_id" : "1",
"_version" : 1,
"exists" : true,
"_source" : {
"nid":"1",

"status":"1",

"title":"Hello elasticsearch”,
"body":"First elasticsearch document"
}
}
Let's GET some data
Get specific fields
> GET /mysite/node/1?fields=title,body
Get source only
> GET /mysite/node/1/_source
Let's UPDATE some
data
> PUT /mysite/node/1
{
“status":"0"
}
Let's UPDATE some
data
> PUT /mysite/node/1
{
"status":"0"
}
{

"ok":true,
"_index":"mysite",
"_type":"node",
"_id":"1",
"_version":2
}
Let's DELETE some
data
Let's DELETE some
data
> DELETE /mysite/node/1
Let's DELETE some
data
> DELETE /mysite/node/1
{
"ok":true,
"found":true,
"_index":"mysite",
"_type":"node",
"_id":"1",
“_version":3
}
Let's SEARCH for
something
Let's SEARCH for
something
> GET /_search
{
"took" : 32,
"timed_out" : false,
"_shards" : {
"total" : 20,
"successful" : 20,
"failed" : 0
},
"hits" : { results... }
}
Let's SEARCH in
multiple indices and
types
Let's SEARCH in
multiple indices and
types
> GET /index/_search
> GET /index1,index2/_search
> GET /index/type/_search


> GET /myapp_*/type, entity_*/_search
Let's PAGINATE
results
Let's PAGINATE
results
> GET /_search?size=10&from=20
size = results per page
from = starting from
Let's search oldschool
Let's search oldschool
> GET /_search?q=title:elasticsearch
> GET /_search?q=nid:60
Query DSL style
Query DSL style
> GET /_search?size=10&from=20
{
"query": {

“match": "awesome"
}
}
Query DSL style
> GET /_search?size=10&from=20
{

"query": {
"field" : {
"title" : {
“query" : "+awesome -poor",
"boost" : 2.0,
}
}
}
}
Queries & Filters
Queries & Filters
full text search exact match
relevance score show or hide
heavy lightning fast

not cacheable cacheable
Combine Filters &
Queries
Combine Filters &
Queries
{

"query": {
"filtered": {
"query": {
"match": {
"title": "awesome"
}
},
"filter": {

"term": {
"type": "article"
}
}
}
}
}
> GET /_search
Sorting
Sorting
{

"query": {
"filtered": {
"query": {
“match": { "title": "awesome" }
},
"filter": {

"term": { "type": "article" }
}
}
}
"sort": {"date":"desc"}
}
> GET /_search
and Facets
"aggregations" : {
"<aggregation_name>" : {
"<aggregation_type>" : {
<aggregation_body>
}
[,"meta" : { [<meta_data_body>] } ]?
[,"aggregations" : { [<sub_aggregation>]+ } ]?
}
[,"<aggregation_name_2>" : { ... } ]*
}
and Facets
> GET /_search
{
"aggregations": {
"home_team": {
"terms": {

"field": “field_home_team"
}
}
}
}
and Facets
> GET /_search
{
"aggregations": {
"home_team": {
"terms": {

"field": “field_home_team"
}
}
}
}
Give your facet a name
and Facets
> GET /_search
{
"aggregations": {
"home_team": {
"terms": {

"field": “field_home_team"
}
}
}
}
Your facet filter can be:
● Terms

● Range

● Histogram

● Date Histogram ● Filter

● Query

● Statistical

● Terms Stats

● Geo Distance

● Cardinality

● Nested
and Facets
"aggregations" : {
"home_team" : {
"_type" : "terms",
"missing" : 203,
"total" : 100,
"other" : 42,
"terms" : [ {
"term" : "hou",
"count" : 8
}, {

"term" : "sln",
"count" : 6
}, ...
STOP! I want this
in Drupal
STOP! I want this
in Drupal
Available modules:
Search API + elasticsearch_connector
Let the Search be with you

DRUPAL AND ELASTICSEARCH

  • 1.
  • 2.
    Flexible and powerfulopen source, distributed real-time search and analytics engine for the cloud Elasticsearch
  • 3.
    Flexible and powerfulopen source, distributed real-time search and analytics engine for the cloud Elasticsearch RESTful API on top of Lucene library
  • 4.
  • 5.
    Why use Elasticsearch? ● RESTfulAPI 
 ● Open Source 
 ● JSON over HTTP 
 ● based on Lucene 
 ● distributed 
 ● highly available 
 ● schema free 
 ● massively scalable 

  • 7.
  • 8.
    How to useit? > curl -XGET localhost:9200/?pretty
  • 9.
    How to useit? > curl -XGET localhost:9200/?pretty {
 "ok" : true, "status" : 200, "name" : "Infinity", "version" : { "number" : "0.90.1", "snapshot_build" : false, "lucene_version" : "4.3" }, "tagline" : "You Know, for Search" }
  • 10.
    How to useit? > curl -XGET localhost:9200/?pretty action
  • 11.
    How to useit? > curl -XGET localhost:9200/?pretty node + port
  • 12.
    How to useit? > curl -XGET localhost:9200/?pretty path
  • 13.
    How to useit? > curl -XGET localhost:9200/?pretty query string
  • 14.
  • 15.
    Let's index somedata > PUT /index/type/id Where? It's very similar to database in SQL
  • 16.
    Let's index somedata > PUT /index/type/id What? Table
 Content type,
 Entity type,
 any kind of type you decide
  • 17.
    Let's index somedata > PUT /index/type/id Which? Node ID, Entity ID,
 any kind of serial ID
  • 18.
    Let's index somedata > PUT /mysite/node/1 {
 "nid": "1", "status": "1",
 "title": "Hello elasticsearch",
 "body": "First elasticsearch document" }
  • 19.
    Let's index somedata > PUT /mysite/node/1 -d { "nid": "1", "status": "1",
 "title": "Hello elasticsearch",
 "body": "First elasticsearch document" } {
 "ok":true, "_index":"mysite", "_type":"node", "_id":"1", "_version":1 }
  • 20.
  • 21.
    Let's GET somedata > GET /mysite/node/1 {
 "_index" : "mysite", "_type" : "node", "_id" : "1", "_version" : 1, "exists" : true, "_source" : { "nid":"1",
 "status":"1",
 "title":"Hello elasticsearch”, "body":"First elasticsearch document" } }
  • 22.
    Let's GET somedata Get specific fields > GET /mysite/node/1?fields=title,body Get source only > GET /mysite/node/1/_source
  • 23.
    Let's UPDATE some data >PUT /mysite/node/1 { “status":"0" }
  • 24.
    Let's UPDATE some data >PUT /mysite/node/1 { "status":"0" } {
 "ok":true, "_index":"mysite", "_type":"node", "_id":"1", "_version":2 }
  • 25.
  • 26.
    Let's DELETE some data >DELETE /mysite/node/1
  • 27.
    Let's DELETE some data >DELETE /mysite/node/1 { "ok":true, "found":true, "_index":"mysite", "_type":"node", "_id":"1", “_version":3 }
  • 28.
  • 29.
    Let's SEARCH for something >GET /_search { "took" : 32, "timed_out" : false, "_shards" : { "total" : 20, "successful" : 20, "failed" : 0 }, "hits" : { results... } }
  • 30.
    Let's SEARCH in multipleindices and types
  • 31.
    Let's SEARCH in multipleindices and types > GET /index/_search > GET /index1,index2/_search > GET /index/type/_search 
 > GET /myapp_*/type, entity_*/_search
  • 32.
  • 33.
    Let's PAGINATE results > GET/_search?size=10&from=20 size = results per page from = starting from
  • 34.
  • 35.
    Let's search oldschool >GET /_search?q=title:elasticsearch > GET /_search?q=nid:60
  • 36.
  • 37.
    Query DSL style >GET /_search?size=10&from=20 { "query": {
 “match": "awesome" } }
  • 38.
    Query DSL style >GET /_search?size=10&from=20 {
 "query": { "field" : { "title" : { “query" : "+awesome -poor", "boost" : 2.0, } } } }
  • 39.
  • 40.
    Queries & Filters fulltext search exact match relevance score show or hide heavy lightning fast
 not cacheable cacheable
  • 41.
  • 42.
    Combine Filters & Queries {
 "query":{ "filtered": { "query": { "match": { "title": "awesome" } }, "filter": {
 "term": { "type": "article" } } } } } > GET /_search
  • 43.
  • 44.
    Sorting {
 "query": { "filtered": { "query":{ “match": { "title": "awesome" } }, "filter": {
 "term": { "type": "article" } } } } "sort": {"date":"desc"} } > GET /_search
  • 45.
    and Facets "aggregations" :{ "<aggregation_name>" : { "<aggregation_type>" : { <aggregation_body> } [,"meta" : { [<meta_data_body>] } ]? [,"aggregations" : { [<sub_aggregation>]+ } ]? } [,"<aggregation_name_2>" : { ... } ]* }
  • 46.
    and Facets > GET/_search { "aggregations": { "home_team": { "terms": {
 "field": “field_home_team" } } } }
  • 47.
    and Facets > GET/_search { "aggregations": { "home_team": { "terms": {
 "field": “field_home_team" } } } } Give your facet a name
  • 48.
    and Facets > GET/_search { "aggregations": { "home_team": { "terms": {
 "field": “field_home_team" } } } } Your facet filter can be: ● Terms
 ● Range
 ● Histogram
 ● Date Histogram ● Filter
 ● Query
 ● Statistical
 ● Terms Stats
 ● Geo Distance
 ● Cardinality
 ● Nested
  • 49.
    and Facets "aggregations" :{ "home_team" : { "_type" : "terms", "missing" : 203, "total" : 100, "other" : 42, "terms" : [ { "term" : "hou", "count" : 8 }, {
 "term" : "sln", "count" : 6 }, ...
  • 50.
    STOP! I wantthis in Drupal
  • 51.
    STOP! I wantthis in Drupal Available modules: Search API + elasticsearch_connector
  • 52.
    Let the Searchbe with you