SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Elastic Search
Concepts
• Elastic search is an open source(Apache 2), Distributed, RESTful,
Search Engine built on top of Apache Lucene
• Schema Free & Document Oriented
• Support JSON Model
• Elastic Search allows you to completely control how a JSON
document gets mapped into the search on a per type and per
index level.
• Multi Tenancy – Support for more than one index, support for
more than one type per index
• Distributed Nature - Indices are broken down into shards, each
shard with 0 or more replicas
• In RDBMS terms, index corresponds to database, type
corresponds to table, a document corresponds to a table row and
a field corresponds to a table column.
Create Index
• The create index API allows to instantiate an index
• Curl Example for making Sales index (index name should be in lowercase)
$ curl -XPOST 'http://localhost:9200/sales/‘

• Each index created can have specific settings associated with it. Following
example create index sales with 3 shards, each with 2 replicas
curl - XPOST 'http://localhost:9200/sales/' -d '{
"settings" : {
"number_of_shards" : 3,
"number_of_replicas" : 2
}
}‘
• Reference link :
http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index.html
Mapping
• Mapping is the process of defining how a document should be mapped to
the Search Engine
• If no mapping is defined, elasticsearch will guess the kind of the data and
map it.
• In ES, an index may store documents of different “mapping types”
• The put mapping API allows to register specific mapping definition for a
specific type. Example – mapping for Order type
curl -XPOST 'http://localhost:9200/sales/order1/_mapping' -d '
{
"order1":
{
"properties":
{
"entity_id":{"type":"integer"},
"increment_id":{"type":"string","index":"not_analyzed"},
"status":{"type":"string"}
}
}
}‘
Mapping
• Get Mapping available in index.
Following curl examples returned all the type and its associate
mapping available in sales index
curl –XGET ‘localhost:9200/sales/_mapping?pretty=1’

• Get Mapping of type
curl – XGET‘localhost:9200/sales/order1/_mapping?pretty=1’

• Reference link :
http://www.elasticsearch.org/guide/reference/mapping/index.html
Add document
• The following example inserts the JSON document into the
“sales” index, under a type called “order1” with an id of 1:
curl -XPOST 'http://localhost:9200/sales/order1/1' -d '
{
"entity_id":1,
"increment_id":"1000001",
“status":"shipped",
}'

• Reference link:
http://www.elasticsearch.org/guide/reference/api/index_.html
GET API (Get data)
• The get API allows to get a typed JSON document from the
index based on its id. The following example gets a JSON
document from an index called sales, under a type called
order1, with id valued 1:
curl -XGET 'localhost:9200/sales/order1/1?pretty=1'

• The get operation allows to specify a set of fields that will be
returned by passing the fields parameter. For example:
curl -XGET 'localhost:9200/sales/order/1?fields=entity_id?pretty=1‘

• Reference link :
http://www.elasticsearch.org/guide/reference/api/get.html

• For Multi Get Api
http://www.elasticsearch.org/guide/reference/api/multi-get.html
Search API (Search data)
•

The search API allows to execute a search query and get back search hits that
match the query. Following query returns the document which have entity_id
1
curl -XGET 'http://localhost:9200/sales/order1/_search' -d '{
"query" : {
"term" : { “entity_id" : 1 }
}
}
'

•

•

The additional parameter for search API are from, size, search_type, sort,fields
etc.
curl -XGET 'http://localhost:9200/sales/order1/_search' -d '{
"query" : {
"term" : {"status" : "confirmed" }
},
"from" :0, "size" :1,"sort" :[{"entity_id" : "desc"],"fields":["entity_id","increment_id"]
}
‘
Reference Link :
http://www.elasticsearch.org/guide/reference/api/search/request-body.html
Multi - Search API (Search data)
• The search API can be applied to multiple types within an index,
and across multiple indices with support for the multi index syntax.
For example, we can search on all documents across all types within
the sales index:
curl -XGET 'http://localhost:9200/sales/_search?q=status:confirmed‘

• We can also search within specific types:
curl -XGET 'http://localhost:9200/sales/order,order1/_search?q=status:confirmed‘

• We can also search all orders with a certain field across several
indices:
curl -XGET 'http://localhost:9200/sales,newsales/order1/_search?q=entity_id:1‘

• we can search all orders across all available indices using _all
placeholder:
curl - XGET 'http://localhost:9200/_all/order1/_search?q=entity_id:1‘

• even search across all indices and all types:
curl -XGET 'http://localhost:9200/_search?q=entity_id:1'
Update API
• The update API allows to update a document based on a script
provided. Following example update the status field of document
which has id 1 with new value.
curl -XPOST 'localhost:9200/sales/order1/1/_update' -d '{
"script" : "ctx._source.status= newStatus",
"params" : {
"newStatus" : " confirmed"
}
}‘

• We can also add a new field to the document:
curl -XPOST 'localhost:9200/sales/order1/1/_update' -d '{
"script" : "ctx._source.newField = "new field intoduced""
}‘

• We can also remove a field from the document:
curl -XPOST 'localhost:9200/sales/order1/1/_update' -d '{
"script" : "ctx._source.remove("newField")"
}‘

• Reference link :
http://www.elasticsearch.org/guide/reference/api/update.html
Delete API
• The delete API allows to delete a typed JSON document from a
specific index based on its id. The following example deletes the
JSON document from an index called sales, under a type called
order1, with id valued 1:
curl -XDELETE 'http://localhost:9200/sales/order1/1‘

• Delete entire type
curl -XDELETE 'http://localhost:9200/sales/order1‘

• The delete by query API allows to delete documents from one or
more indices and one or more types based on a query:
curl -XDELETE 'http://localhost:9200/sales/order1/_query?q=entity_id:1‘
curl -XDELETE 'http://localhost:9200/sales/_query?q=entity_id:1'
curl -XDELETE 'http://localhost:9200/sales/order1/_query' -d '{
"term" : { “status" : “confirmed" }
}'
Count API

• The count API allows to easily execute a query and get the number of
matches for that query. It can be executed across one or more indices and
across one or more types.
curl -XGET 'http://localhost:9200/sales/order/_count' -d '
{
"term":{"status":"confirmed"}
}'
curl -XGET 'http://localhost:9200/_count' -d '
{
"term":{"status":"confirmed"}
}'
curl -XGET 'http://localhost:9200/sales/order,order1/_count' -d '
{
"term":{"status":"confirmed"}
}'

• Reference Link :
http://www.elasticsearch.org/guide/reference/api/count.html
Facet Search

• Facets provide aggregated data based on a search query.
• A terms facet can return facet counts for various facet values for a
specific field. ElasticSearch supports more facet implementations,
such as range, statistical or date histogram facets.
• The field used for facet calculations must be of type numeric,
date/time or be analyzed as a single token.
• You can give the facet a custom name and return multiple facets in
one request.
• Now, let’s query the index for products which has category id 3 and
retrieve a terms facet for the brands field. We will name the facet
simply: Brands (Example of facet terms)
curl -XGET 'localhost:9200/category/products/_search?pretty=1' -d '
{
"query": {"term":{"category_id":3} },
"facets":
{
"Brands": {"terms":{"fields":["brands"],"size":10,"order":"term"}}
}
}'

•

Reference link:
http://www.elasticsearch.org/guide/reference/api/search/facets/
http://www.elasticsearch.org/guide/reference/api/search/facets/terms-facet.html
•

Facet search
Range facet allows to specify a set of ranges and get both the number of docs
(count) that fall within each range, and aggregated data either based on the field,
or using another field.
curl -XGET 'localhost:9200/sales/order/_search?pretty=1' -d '
{
"query" : {"term" : {"status" : "confirmed"} },
"facets" : {
"range1" : {
"range" : {
"grand_total" : [
{ "to" : 50 },
{ "from" : 20, "to" : 70 },
{ "from" : 70, "to" : 120 },
{ "from" : 150 }
]
}
}
},
"sort":[{"entity_id":"asc"}]
}'

• Reference link :
http://www.elasticsearch.org/guide/reference/api/search/facets/range-facet.html
Elastica

• Elastica is an Open Source PHP client for the elasticsearch search
engine/database.
• Reference Link : http://www.elastica.io/en
• To use Elastica, Download and Include Elastica in a project using PHP
autoload.
function __autoload_elastica ($class)
{
$path = str_replace('_', '/', $class);
if (file_exists('/xampp/htdocs/project/Elastica/lib/' . $path . '.php'))
{
require_once('/xampp/htdocs/project/Elastica/lib/' . $path . '.php');
}
}
spl_autoload_register('__autoload_elastica');

• Connecting to ElasticSearch:
On single node :
$elasticaClient- = new Elastica_Client(array('host' => '192.168.0.27','port' => '9200'));

• It is quite easy to start a elasticsearch cluster simply by starting multiple
instances of elasticsearch on one server or on multiple servers. One of the
goals of the distributed search index is availability. If one server goes
down, search results should still be served.
$elasticaClient- = new Elastica_Client('servers'=>array(array('host' =>
'192.168.0.27','port' => '9200'), array('host' => '192.168.0.27','port' => '9201')));
• Create Index :

Elastica

$elasticaClient- = new Elastica_Client(array('host' =>
'192.168.0.27','port' => '9200'));
$elasticaIndex = $elasticaClient->getIndex(‘sales');
$elasticaIndex->create(
array( 'number_of_shards' => 4, 'number_of_replicas' => 1), true);

• Define Mapping :
$mapping = new Elastica_Type_Mapping();
$elasticaIndex = $elasticaClient- >getIndex('sales');
$elasticaType = $elasticaIndex->getType('order');
$mapping->setType($elasticaType);
$mapping->setProperties(array(
'entity_id' => array('type' => 'integer'),
'increment_id' => array('type' => 'string',"index" => "not_analyzed"),
‘status' =>array('type'=>'string',"index" => "not_analyzed")
));
$mapping->send();
Elastica Add documents
$elasticaClient- = new Elastica_Client(array('host' => '192.168.0.27','port' =>
'9200'));
$elasticaIndex = $elasticaClient ->getIndex('sales');
$elasticaType = $elasticaIndex->getType('order');
// The Id of the document
$id = 1;
// Create a document
$record = array('entity_id'=>1,
‘increment_id'=>‘100001',‘status'=>‘confirmed');
$recordDocument = new Elastica_Document($id, $record);
// Add record to type
$elasticaType->addDocument($ recordDocument );
// Refresh Index
$elasticaType->getIndex()->refresh();
Elastica Get Document
$elasticaClient- = new Elastica_Client(array('host' =>
'192.168.0.27','port' => '9200'));
$index = $elasticaClient->getIndex('sales');
//get index
$type = $index->getType('order');
//get type
$Doc = $type->getDocument($id)->getData(); //get data
Elastica Update Document
$elasticaClient- = new Elastica_Client(array('host' => '192.168.0.27','port' => '9200'));
$index = $elasticaClient->getIndex('sales');
//get index
$type = $index->getType('order');
//get type
$id = 1;
//id of document which need to be updated
$newVal = 'confirmed';
//value to be updated
$update = new Elastica_Script("ctx._source.status = newval", array('newval' => $newVal));
$res=$type->updateDocument($id,$update);
if(!empty($res))
{
$val=$res->getData();
if($val['ok'])
{
echo "updated";
}
else
{
echo “value not updated";
}
}
else
{
echo “value not updated";
}
Elastica Search Documents
• The search API allows to execute a search query and get back
search hits that match the query.
• Search API consists following major methods:
– Query String
– Term
– Terms
– Range
– Bool Query
– Filter (it also contain Filter_term, Filter_Range etc)
– Facets (it contain Facet_Range, Facet_Terms,Facet_Filter,
Facet_Query, Facet_statistical etc.)
– Query (where we can set fields for output, limit , sorting)
Search Documents – Query String
$elasticaClient = new Elastica_Client(array('host' => '192.168.0.27','port' => '9200'));
$elasticaIndex = $elasticaClient->getIndex('sales');
$elasticaType = $elasticaIndex->getType('order');
$elasticaQueryString = new Elastica_Query_QueryString();
$elasticaQueryString->setQuery((string) “shipped*");
$elasticaQueryString->setFields(array(‘status')); //we can set 1 or more than 1 field in query string
$elasticaQuery = new Elastica_Query();
$elasticaQuery->setQuery($elasticaQueryString);
$elasticaQuery->setFields(array('increment_id','entity_id','billing_name','grand_total'));
$elasticaQuery->setFrom(0);
$elasticaQuery->setLimit(20);
$sort = array("entity_id" => "desc");
$elasticaQuery->setSort($sort);
$elasticaResultSet = $elasticaType->search($elasticaQuery);
$totalResults = $ elasticaResultSet ->getTotalHits();
$elasticaResults = $elasticaResultSet ->getResults();
foreach ($elasticaResults as $elasticaResult)
{
print_r($elasticaResult->getData());
Search Documents – Query Term
$elasticaQueryTerm = new Elastica_Query_Term();
$elasticaQueryTerm->setTerm('entity_id',1);
$elasticaQuery = new Elastica_Query();
$elasticaQuery->setQuery($elasticaQueryTerm);
$elasticaQuery->setFields(array('increment_id','entity_id','billing_name','grand_total'));
$elasticaQuery->setFrom(0);
$elasticaQuery->setLimit(20);
$sort = array("entity_id" => “asc");
$elasticaQuery->setSort($sort);
$elasticaResultSet = $elasticaType->search($elasticaQuery);
Search Documents – Query Terms
$elasticaQueryTerms = new Elastica_Query_Terms();
//for query terms, you can specify 1 or more than 1 value per field
$elasticaQueryTerms->setTerms('entity_id', array(1,2,3,4,5));
$elasticaQueryTerms->addTerm(6);
$elasticaQuery = new Elastica_Query();
$elasticaQuery->setQuery($elasticaQueryTerms);
$elasticaQuery->setFields(array('increment_id','entity_id','billing_name','grand_total'));
$elasticaQuery->setFrom(0);
$elasticaQuery->setLimit(20);
$sort = array("entity_id" => “asc");
$elasticaQuery->setSort($sort);
$elasticaResultSet = $elasticaType->search($elasticaQuery);
Search Documents – Query Range
$elasticaQueryRange = new Elastica_Query_Range();

//for range query , you can specify from, from & to or to only
$elasticaQueryRange->addField('entity_id', array('from' => 10,"to"=>14));
$elasticaQuery = new Elastica_Query();
$elasticaQuery->setQuery($elasticaQueryRange);
$elasticaQuery->setFields(array('increment_id','entity_id','billing_name','grand_total'));
$elasticaQuery->setFrom(0);
$elasticaQuery->setLimit(20);
$sort = array("entity_id" => “asc");
$elasticaQuery->setSort($sort);
$elasticaResultSet = $elasticaType->search($elasticaQuery);
Search Documents – Bool Query
•
•

The bool query maps to Lucene BooleanQuery
Bool Query contains clause Occurrence – must, should, must_not
$boolQuery = new Elastica_Query_Bool();
$elasticaQueryString = new Elastica_Query_QueryString();
$elasticaQueryString ->setQuery(‘shoh*');
$elasticaQueryString->setFields(array('‘billing_name, ‘shipping_name'));
$boolQuery->addMust($elasticaQueryString);
$elasticaQueryTerm = new Elastica_Query_Term();
$elasticaQueryTerm->setTerm('entity_id',1);
$boolQuery->addMust($elasticaQueryTerm );
$elasticaQuery = new Elastica_Query();
$elasticaQuery->setQuery($boolQuery);
$elasticaResultSet = $elasticaType->search($elasticaQuery);
Search Documents – Query Filters
•

When doing things like facet navigation, sometimes only the hits are needed to be filtered by
the chosen facet, and all the facets should continue to be calculated based on the original
query. The filter element within the search request can be used to accomplish it.

$elasticaQueryString
= new Elastica_Query_QueryString();
$elasticaQueryString->setQuery('*');
$elasticaQueryString->setFields(array('increment_id'));
$filteredQuery = new Elastica_Query_Filtered($elasticaQueryString,new
Elastica_Filter_Range('created_at', array('from' => '2011-01-04 07:36:00','to' => '2013-01-04
19:36:25')));
$elasticaQuery
= new Elastica_Query();
$elasticaQuery->setQuery($filteredQuery);
$elasticaResultSet = $elasticaType->search($elasticaQuery);
Elastica - Facet Terms
$elasticaQuery = new Elastica_Query();
$elasticaQuery->setQuery($boolQuery);
//set main query
$facet = new Elastica_Facet_Terms('status Facet');
$facet->setField('status');
$facet->setOrder(‘term');
//another options are reverse_term,count,reverse_count
$facet->setSize(5);
$elasticaQuery->addFacet($facet);

//adding facet to query

$elasticaResultSet = $elasticaType->search($elasticaQuery);
$facets = $ elasticaResultSet ->getFacets(); //get facets data
foreach($facets as $k=>$v)
{
if(isset($v['terms']) && is_array($v['terms']))
{
$data['facets'][$k]=$v['terms'];
}
}

Weitere ähnliche Inhalte

Was ist angesagt?

Deep Dive Into Elasticsearch
Deep Dive Into ElasticsearchDeep Dive Into Elasticsearch
Deep Dive Into ElasticsearchKnoldus Inc.
 
Elastic search overview
Elastic search overviewElastic search overview
Elastic search overviewABC Talks
 
quick intro to elastic search
quick intro to elastic search quick intro to elastic search
quick intro to elastic search medcl
 
Elastic Search (엘라스틱서치) 입문
Elastic Search (엘라스틱서치) 입문Elastic Search (엘라스틱서치) 입문
Elastic Search (엘라스틱서치) 입문SeungHyun Eom
 
차곡차곡 쉽게 알아가는 Elasticsearch와 Node.js
차곡차곡 쉽게 알아가는 Elasticsearch와 Node.js차곡차곡 쉽게 알아가는 Elasticsearch와 Node.js
차곡차곡 쉽게 알아가는 Elasticsearch와 Node.jsHeeJung Hwang
 
Elasticsearch Tutorial | Getting Started with Elasticsearch | ELK Stack Train...
Elasticsearch Tutorial | Getting Started with Elasticsearch | ELK Stack Train...Elasticsearch Tutorial | Getting Started with Elasticsearch | ELK Stack Train...
Elasticsearch Tutorial | Getting Started with Elasticsearch | ELK Stack Train...Edureka!
 
Workshop: Learning Elasticsearch
Workshop: Learning ElasticsearchWorkshop: Learning Elasticsearch
Workshop: Learning ElasticsearchAnurag Patel
 
elasticsearch_적용 및 활용_정리
elasticsearch_적용 및 활용_정리elasticsearch_적용 및 활용_정리
elasticsearch_적용 및 활용_정리Junyi Song
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMike Dirolf
 
Centralized log-management-with-elastic-stack
Centralized log-management-with-elastic-stackCentralized log-management-with-elastic-stack
Centralized log-management-with-elastic-stackRich Lee
 
Elasticsearch for beginners
Elasticsearch for beginnersElasticsearch for beginners
Elasticsearch for beginnersNeil Baker
 
Introduction to Elasticsearch
Introduction to ElasticsearchIntroduction to Elasticsearch
Introduction to ElasticsearchIsmaeel Enjreny
 
Bucketing 2.0: Improve Spark SQL Performance by Removing Shuffle
Bucketing 2.0: Improve Spark SQL Performance by Removing ShuffleBucketing 2.0: Improve Spark SQL Performance by Removing Shuffle
Bucketing 2.0: Improve Spark SQL Performance by Removing ShuffleDatabricks
 
Introduction to elasticsearch
Introduction to elasticsearchIntroduction to elasticsearch
Introduction to elasticsearchpmanvi
 
Running Apache Spark on Kubernetes: Best Practices and Pitfalls
Running Apache Spark on Kubernetes: Best Practices and PitfallsRunning Apache Spark on Kubernetes: Best Practices and Pitfalls
Running Apache Spark on Kubernetes: Best Practices and PitfallsDatabricks
 
Indexing with MongoDB
Indexing with MongoDBIndexing with MongoDB
Indexing with MongoDBMongoDB
 
Introduction to Kibana
Introduction to KibanaIntroduction to Kibana
Introduction to KibanaVineet .
 

Was ist angesagt? (20)

Deep Dive Into Elasticsearch
Deep Dive Into ElasticsearchDeep Dive Into Elasticsearch
Deep Dive Into Elasticsearch
 
Elastic search overview
Elastic search overviewElastic search overview
Elastic search overview
 
quick intro to elastic search
quick intro to elastic search quick intro to elastic search
quick intro to elastic search
 
ELK Stack
ELK StackELK Stack
ELK Stack
 
Elastic Search (엘라스틱서치) 입문
Elastic Search (엘라스틱서치) 입문Elastic Search (엘라스틱서치) 입문
Elastic Search (엘라스틱서치) 입문
 
ELK Stack
ELK StackELK Stack
ELK Stack
 
차곡차곡 쉽게 알아가는 Elasticsearch와 Node.js
차곡차곡 쉽게 알아가는 Elasticsearch와 Node.js차곡차곡 쉽게 알아가는 Elasticsearch와 Node.js
차곡차곡 쉽게 알아가는 Elasticsearch와 Node.js
 
Elasticsearch Tutorial | Getting Started with Elasticsearch | ELK Stack Train...
Elasticsearch Tutorial | Getting Started with Elasticsearch | ELK Stack Train...Elasticsearch Tutorial | Getting Started with Elasticsearch | ELK Stack Train...
Elasticsearch Tutorial | Getting Started with Elasticsearch | ELK Stack Train...
 
Workshop: Learning Elasticsearch
Workshop: Learning ElasticsearchWorkshop: Learning Elasticsearch
Workshop: Learning Elasticsearch
 
elasticsearch_적용 및 활용_정리
elasticsearch_적용 및 활용_정리elasticsearch_적용 및 활용_정리
elasticsearch_적용 및 활용_정리
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Centralized log-management-with-elastic-stack
Centralized log-management-with-elastic-stackCentralized log-management-with-elastic-stack
Centralized log-management-with-elastic-stack
 
Elasticsearch for beginners
Elasticsearch for beginnersElasticsearch for beginners
Elasticsearch for beginners
 
Introduction to Elasticsearch
Introduction to ElasticsearchIntroduction to Elasticsearch
Introduction to Elasticsearch
 
Bucketing 2.0: Improve Spark SQL Performance by Removing Shuffle
Bucketing 2.0: Improve Spark SQL Performance by Removing ShuffleBucketing 2.0: Improve Spark SQL Performance by Removing Shuffle
Bucketing 2.0: Improve Spark SQL Performance by Removing Shuffle
 
Introduction to elasticsearch
Introduction to elasticsearchIntroduction to elasticsearch
Introduction to elasticsearch
 
Running Apache Spark on Kubernetes: Best Practices and Pitfalls
Running Apache Spark on Kubernetes: Best Practices and PitfallsRunning Apache Spark on Kubernetes: Best Practices and Pitfalls
Running Apache Spark on Kubernetes: Best Practices and Pitfalls
 
Indexing with MongoDB
Indexing with MongoDBIndexing with MongoDB
Indexing with MongoDB
 
Introduction to Kibana
Introduction to KibanaIntroduction to Kibana
Introduction to Kibana
 
Row/Column- Level Security in SQL for Apache Spark
Row/Column- Level Security in SQL for Apache SparkRow/Column- Level Security in SQL for Apache Spark
Row/Column- Level Security in SQL for Apache Spark
 

Andere mochten auch

Elastic Search Indexing Internals
Elastic Search Indexing InternalsElastic Search Indexing Internals
Elastic Search Indexing InternalsGaurav Kukal
 
Introduction to Elasticsearch
Introduction to ElasticsearchIntroduction to Elasticsearch
Introduction to ElasticsearchSperasoft
 
Elastic search & patent information @ mtc
Elastic search & patent information @ mtcElastic search & patent information @ mtc
Elastic search & patent information @ mtcArne Krueger
 
James elastic search
James   elastic searchJames   elastic search
James elastic searchLearningTech
 
Simple search with elastic search
Simple search with elastic searchSimple search with elastic search
Simple search with elastic searchmarkstory
 
Power of Elastic Search - nLocate
Power of Elastic Search - nLocatePower of Elastic Search - nLocate
Power of Elastic Search - nLocateAayush Shrestha
 
Ricerche performanti con ElasticSearch sfruttando la potenza e la flessibilit...
Ricerche performanti con ElasticSearch sfruttando la potenza e la flessibilit...Ricerche performanti con ElasticSearch sfruttando la potenza e la flessibilit...
Ricerche performanti con ElasticSearch sfruttando la potenza e la flessibilit...Kelyon Srl
 
Elk - Elasticsearch Logstash Kibana stack explained
Elk - Elasticsearch Logstash Kibana stack explainedElk - Elasticsearch Logstash Kibana stack explained
Elk - Elasticsearch Logstash Kibana stack explainedFederico Panini
 
Scaling real-time search and analytics with Elasticsearch
Scaling real-time search and analytics with ElasticsearchScaling real-time search and analytics with Elasticsearch
Scaling real-time search and analytics with Elasticsearchclintongormley
 
Logstash: Progetto open per l'analisi dei log in tempo reale di architetture ...
Logstash: Progetto open per l'analisi dei log in tempo reale di architetture ...Logstash: Progetto open per l'analisi dei log in tempo reale di architetture ...
Logstash: Progetto open per l'analisi dei log in tempo reale di architetture ...Stefano Dindo
 
Webinar usando graylog para la gestión centralizada de logs
Webinar usando graylog para la gestión centralizada de logsWebinar usando graylog para la gestión centralizada de logs
Webinar usando graylog para la gestión centralizada de logsatSistemas
 
Elasticsearch in 15 minutes
Elasticsearch in 15 minutesElasticsearch in 15 minutes
Elasticsearch in 15 minutesDavid Pilato
 
Amministratori Di Sistema: Adeguamento al Garante Privacy - Log Management e ...
Amministratori Di Sistema: Adeguamento al Garante Privacy - Log Management e ...Amministratori Di Sistema: Adeguamento al Garante Privacy - Log Management e ...
Amministratori Di Sistema: Adeguamento al Garante Privacy - Log Management e ...Simone Onofri
 
Elasticsearch presentation 1
Elasticsearch presentation 1Elasticsearch presentation 1
Elasticsearch presentation 1Maruf Hassan
 

Andere mochten auch (20)

Elastic Search Indexing Internals
Elastic Search Indexing InternalsElastic Search Indexing Internals
Elastic Search Indexing Internals
 
Introduction to Elasticsearch
Introduction to ElasticsearchIntroduction to Elasticsearch
Introduction to Elasticsearch
 
Elastic search
Elastic searchElastic search
Elastic search
 
Elastic search & patent information @ mtc
Elastic search & patent information @ mtcElastic search & patent information @ mtc
Elastic search & patent information @ mtc
 
(Elastic)search in big data
(Elastic)search in big data(Elastic)search in big data
(Elastic)search in big data
 
James elastic search
James   elastic searchJames   elastic search
James elastic search
 
IEEE CLOUD \'11
IEEE CLOUD \'11IEEE CLOUD \'11
IEEE CLOUD \'11
 
Simple search with elastic search
Simple search with elastic searchSimple search with elastic search
Simple search with elastic search
 
Power of Elastic Search - nLocate
Power of Elastic Search - nLocatePower of Elastic Search - nLocate
Power of Elastic Search - nLocate
 
Ricerche performanti con ElasticSearch sfruttando la potenza e la flessibilit...
Ricerche performanti con ElasticSearch sfruttando la potenza e la flessibilit...Ricerche performanti con ElasticSearch sfruttando la potenza e la flessibilit...
Ricerche performanti con ElasticSearch sfruttando la potenza e la flessibilit...
 
Elk - Elasticsearch Logstash Kibana stack explained
Elk - Elasticsearch Logstash Kibana stack explainedElk - Elasticsearch Logstash Kibana stack explained
Elk - Elasticsearch Logstash Kibana stack explained
 
Scaling real-time search and analytics with Elasticsearch
Scaling real-time search and analytics with ElasticsearchScaling real-time search and analytics with Elasticsearch
Scaling real-time search and analytics with Elasticsearch
 
Introduction to Elasticsearch
Introduction to ElasticsearchIntroduction to Elasticsearch
Introduction to Elasticsearch
 
Logstash: Progetto open per l'analisi dei log in tempo reale di architetture ...
Logstash: Progetto open per l'analisi dei log in tempo reale di architetture ...Logstash: Progetto open per l'analisi dei log in tempo reale di architetture ...
Logstash: Progetto open per l'analisi dei log in tempo reale di architetture ...
 
Webinar usando graylog para la gestión centralizada de logs
Webinar usando graylog para la gestión centralizada de logsWebinar usando graylog para la gestión centralizada de logs
Webinar usando graylog para la gestión centralizada de logs
 
Elasticsearch in 15 minutes
Elasticsearch in 15 minutesElasticsearch in 15 minutes
Elasticsearch in 15 minutes
 
Elastic Search
Elastic SearchElastic Search
Elastic Search
 
Amministratori Di Sistema: Adeguamento al Garante Privacy - Log Management e ...
Amministratori Di Sistema: Adeguamento al Garante Privacy - Log Management e ...Amministratori Di Sistema: Adeguamento al Garante Privacy - Log Management e ...
Amministratori Di Sistema: Adeguamento al Garante Privacy - Log Management e ...
 
Elasticsearch presentation 1
Elasticsearch presentation 1Elasticsearch presentation 1
Elasticsearch presentation 1
 
Lucene basics
Lucene basicsLucene basics
Lucene basics
 

Ähnlich wie Elastic search Walkthrough

Elastic Search Training#1 (brief tutorial)-ESCC#1
Elastic Search Training#1 (brief tutorial)-ESCC#1Elastic Search Training#1 (brief tutorial)-ESCC#1
Elastic Search Training#1 (brief tutorial)-ESCC#1medcl
 
Elastic search intro-@lamper
Elastic search intro-@lamperElastic search intro-@lamper
Elastic search intro-@lampermedcl
 
曾勇 Elastic search-intro
曾勇 Elastic search-intro曾勇 Elastic search-intro
曾勇 Elastic search-introShaoning Pan
 
Ako prepojiť aplikáciu s Elasticsearch
Ako prepojiť aplikáciu s ElasticsearchAko prepojiť aplikáciu s Elasticsearch
Ako prepojiť aplikáciu s Elasticsearchbart-sk
 
Intro to Elasticsearch
Intro to ElasticsearchIntro to Elasticsearch
Intro to ElasticsearchClifford James
 
Real-time search in Drupal with Elasticsearch @Moldcamp
Real-time search in Drupal with Elasticsearch @MoldcampReal-time search in Drupal with Elasticsearch @Moldcamp
Real-time search in Drupal with Elasticsearch @MoldcampAlexei Gorobets
 
Elasticsearch, a distributed search engine with real-time analytics
Elasticsearch, a distributed search engine with real-time analyticsElasticsearch, a distributed search engine with real-time analytics
Elasticsearch, a distributed search engine with real-time analyticsTiziano Fagni
 
ElasticSearch for .NET Developers
ElasticSearch for .NET DevelopersElasticSearch for .NET Developers
ElasticSearch for .NET DevelopersBen van Mol
 
ELK - What's new and showcases
ELK - What's new and showcasesELK - What's new and showcases
ELK - What's new and showcasesAndrii Gakhov
 
Elasticsearch und die Java-Welt
Elasticsearch und die Java-WeltElasticsearch und die Java-Welt
Elasticsearch und die Java-WeltFlorian Hopf
 
Elasticsearch an overview
Elasticsearch   an overviewElasticsearch   an overview
Elasticsearch an overviewAmit Juneja
 
Elasticsearch intro output
Elasticsearch intro outputElasticsearch intro output
Elasticsearch intro outputTom Chen
 
MongoDB Days UK: Building Apps with the MEAN Stack
MongoDB Days UK: Building Apps with the MEAN StackMongoDB Days UK: Building Apps with the MEAN Stack
MongoDB Days UK: Building Apps with the MEAN StackMongoDB
 

Ähnlich wie Elastic search Walkthrough (20)

Elastic Search Training#1 (brief tutorial)-ESCC#1
Elastic Search Training#1 (brief tutorial)-ESCC#1Elastic Search Training#1 (brief tutorial)-ESCC#1
Elastic Search Training#1 (brief tutorial)-ESCC#1
 
All about elasticsearch language clients
All about elasticsearch language clientsAll about elasticsearch language clients
All about elasticsearch language clients
 
Elastic search intro-@lamper
Elastic search intro-@lamperElastic search intro-@lamper
Elastic search intro-@lamper
 
Elasticsearch
ElasticsearchElasticsearch
Elasticsearch
 
曾勇 Elastic search-intro
曾勇 Elastic search-intro曾勇 Elastic search-intro
曾勇 Elastic search-intro
 
Ako prepojiť aplikáciu s Elasticsearch
Ako prepojiť aplikáciu s ElasticsearchAko prepojiť aplikáciu s Elasticsearch
Ako prepojiť aplikáciu s Elasticsearch
 
Elastic Search
Elastic SearchElastic Search
Elastic Search
 
Intro to Elasticsearch
Intro to ElasticsearchIntro to Elasticsearch
Intro to Elasticsearch
 
Elasticsearch as a Database?
Elasticsearch as a Database?Elasticsearch as a Database?
Elasticsearch as a Database?
 
Real-time search in Drupal with Elasticsearch @Moldcamp
Real-time search in Drupal with Elasticsearch @MoldcampReal-time search in Drupal with Elasticsearch @Moldcamp
Real-time search in Drupal with Elasticsearch @Moldcamp
 
Elasticsearch, a distributed search engine with real-time analytics
Elasticsearch, a distributed search engine with real-time analyticsElasticsearch, a distributed search engine with real-time analytics
Elasticsearch, a distributed search engine with real-time analytics
 
ElasticSearch for .NET Developers
ElasticSearch for .NET DevelopersElasticSearch for .NET Developers
ElasticSearch for .NET Developers
 
Elasticsearch as a Database?
Elasticsearch as a Database?Elasticsearch as a Database?
Elasticsearch as a Database?
 
ELK - What's new and showcases
ELK - What's new and showcasesELK - What's new and showcases
ELK - What's new and showcases
 
Elasticsearch und die Java-Welt
Elasticsearch und die Java-WeltElasticsearch und die Java-Welt
Elasticsearch und die Java-Welt
 
ElasticSearch
ElasticSearchElasticSearch
ElasticSearch
 
Elasticsearch an overview
Elasticsearch   an overviewElasticsearch   an overview
Elasticsearch an overview
 
Elasticsearch intro output
Elasticsearch intro outputElasticsearch intro output
Elasticsearch intro output
 
Elasticsearch
ElasticsearchElasticsearch
Elasticsearch
 
MongoDB Days UK: Building Apps with the MEAN Stack
MongoDB Days UK: Building Apps with the MEAN StackMongoDB Days UK: Building Apps with the MEAN Stack
MongoDB Days UK: Building Apps with the MEAN Stack
 

Kürzlich hochgeladen

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 

Kürzlich hochgeladen (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Elastic search Walkthrough

  • 2. Concepts • Elastic search is an open source(Apache 2), Distributed, RESTful, Search Engine built on top of Apache Lucene • Schema Free & Document Oriented • Support JSON Model • Elastic Search allows you to completely control how a JSON document gets mapped into the search on a per type and per index level. • Multi Tenancy – Support for more than one index, support for more than one type per index • Distributed Nature - Indices are broken down into shards, each shard with 0 or more replicas • In RDBMS terms, index corresponds to database, type corresponds to table, a document corresponds to a table row and a field corresponds to a table column.
  • 3. Create Index • The create index API allows to instantiate an index • Curl Example for making Sales index (index name should be in lowercase) $ curl -XPOST 'http://localhost:9200/sales/‘ • Each index created can have specific settings associated with it. Following example create index sales with 3 shards, each with 2 replicas curl - XPOST 'http://localhost:9200/sales/' -d '{ "settings" : { "number_of_shards" : 3, "number_of_replicas" : 2 } }‘ • Reference link : http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index.html
  • 4. Mapping • Mapping is the process of defining how a document should be mapped to the Search Engine • If no mapping is defined, elasticsearch will guess the kind of the data and map it. • In ES, an index may store documents of different “mapping types” • The put mapping API allows to register specific mapping definition for a specific type. Example – mapping for Order type curl -XPOST 'http://localhost:9200/sales/order1/_mapping' -d ' { "order1": { "properties": { "entity_id":{"type":"integer"}, "increment_id":{"type":"string","index":"not_analyzed"}, "status":{"type":"string"} } } }‘
  • 5. Mapping • Get Mapping available in index. Following curl examples returned all the type and its associate mapping available in sales index curl –XGET ‘localhost:9200/sales/_mapping?pretty=1’ • Get Mapping of type curl – XGET‘localhost:9200/sales/order1/_mapping?pretty=1’ • Reference link : http://www.elasticsearch.org/guide/reference/mapping/index.html
  • 6. Add document • The following example inserts the JSON document into the “sales” index, under a type called “order1” with an id of 1: curl -XPOST 'http://localhost:9200/sales/order1/1' -d ' { "entity_id":1, "increment_id":"1000001", “status":"shipped", }' • Reference link: http://www.elasticsearch.org/guide/reference/api/index_.html
  • 7. GET API (Get data) • The get API allows to get a typed JSON document from the index based on its id. The following example gets a JSON document from an index called sales, under a type called order1, with id valued 1: curl -XGET 'localhost:9200/sales/order1/1?pretty=1' • The get operation allows to specify a set of fields that will be returned by passing the fields parameter. For example: curl -XGET 'localhost:9200/sales/order/1?fields=entity_id?pretty=1‘ • Reference link : http://www.elasticsearch.org/guide/reference/api/get.html • For Multi Get Api http://www.elasticsearch.org/guide/reference/api/multi-get.html
  • 8. Search API (Search data) • The search API allows to execute a search query and get back search hits that match the query. Following query returns the document which have entity_id 1 curl -XGET 'http://localhost:9200/sales/order1/_search' -d '{ "query" : { "term" : { “entity_id" : 1 } } } ' • • The additional parameter for search API are from, size, search_type, sort,fields etc. curl -XGET 'http://localhost:9200/sales/order1/_search' -d '{ "query" : { "term" : {"status" : "confirmed" } }, "from" :0, "size" :1,"sort" :[{"entity_id" : "desc"],"fields":["entity_id","increment_id"] } ‘ Reference Link : http://www.elasticsearch.org/guide/reference/api/search/request-body.html
  • 9. Multi - Search API (Search data) • The search API can be applied to multiple types within an index, and across multiple indices with support for the multi index syntax. For example, we can search on all documents across all types within the sales index: curl -XGET 'http://localhost:9200/sales/_search?q=status:confirmed‘ • We can also search within specific types: curl -XGET 'http://localhost:9200/sales/order,order1/_search?q=status:confirmed‘ • We can also search all orders with a certain field across several indices: curl -XGET 'http://localhost:9200/sales,newsales/order1/_search?q=entity_id:1‘ • we can search all orders across all available indices using _all placeholder: curl - XGET 'http://localhost:9200/_all/order1/_search?q=entity_id:1‘ • even search across all indices and all types: curl -XGET 'http://localhost:9200/_search?q=entity_id:1'
  • 10. Update API • The update API allows to update a document based on a script provided. Following example update the status field of document which has id 1 with new value. curl -XPOST 'localhost:9200/sales/order1/1/_update' -d '{ "script" : "ctx._source.status= newStatus", "params" : { "newStatus" : " confirmed" } }‘ • We can also add a new field to the document: curl -XPOST 'localhost:9200/sales/order1/1/_update' -d '{ "script" : "ctx._source.newField = "new field intoduced"" }‘ • We can also remove a field from the document: curl -XPOST 'localhost:9200/sales/order1/1/_update' -d '{ "script" : "ctx._source.remove("newField")" }‘ • Reference link : http://www.elasticsearch.org/guide/reference/api/update.html
  • 11. Delete API • The delete API allows to delete a typed JSON document from a specific index based on its id. The following example deletes the JSON document from an index called sales, under a type called order1, with id valued 1: curl -XDELETE 'http://localhost:9200/sales/order1/1‘ • Delete entire type curl -XDELETE 'http://localhost:9200/sales/order1‘ • The delete by query API allows to delete documents from one or more indices and one or more types based on a query: curl -XDELETE 'http://localhost:9200/sales/order1/_query?q=entity_id:1‘ curl -XDELETE 'http://localhost:9200/sales/_query?q=entity_id:1' curl -XDELETE 'http://localhost:9200/sales/order1/_query' -d '{ "term" : { “status" : “confirmed" } }'
  • 12. Count API • The count API allows to easily execute a query and get the number of matches for that query. It can be executed across one or more indices and across one or more types. curl -XGET 'http://localhost:9200/sales/order/_count' -d ' { "term":{"status":"confirmed"} }' curl -XGET 'http://localhost:9200/_count' -d ' { "term":{"status":"confirmed"} }' curl -XGET 'http://localhost:9200/sales/order,order1/_count' -d ' { "term":{"status":"confirmed"} }' • Reference Link : http://www.elasticsearch.org/guide/reference/api/count.html
  • 13. Facet Search • Facets provide aggregated data based on a search query. • A terms facet can return facet counts for various facet values for a specific field. ElasticSearch supports more facet implementations, such as range, statistical or date histogram facets. • The field used for facet calculations must be of type numeric, date/time or be analyzed as a single token. • You can give the facet a custom name and return multiple facets in one request. • Now, let’s query the index for products which has category id 3 and retrieve a terms facet for the brands field. We will name the facet simply: Brands (Example of facet terms) curl -XGET 'localhost:9200/category/products/_search?pretty=1' -d ' { "query": {"term":{"category_id":3} }, "facets": { "Brands": {"terms":{"fields":["brands"],"size":10,"order":"term"}} } }' • Reference link: http://www.elasticsearch.org/guide/reference/api/search/facets/ http://www.elasticsearch.org/guide/reference/api/search/facets/terms-facet.html
  • 14. • Facet search Range facet allows to specify a set of ranges and get both the number of docs (count) that fall within each range, and aggregated data either based on the field, or using another field. curl -XGET 'localhost:9200/sales/order/_search?pretty=1' -d ' { "query" : {"term" : {"status" : "confirmed"} }, "facets" : { "range1" : { "range" : { "grand_total" : [ { "to" : 50 }, { "from" : 20, "to" : 70 }, { "from" : 70, "to" : 120 }, { "from" : 150 } ] } } }, "sort":[{"entity_id":"asc"}] }' • Reference link : http://www.elasticsearch.org/guide/reference/api/search/facets/range-facet.html
  • 15. Elastica • Elastica is an Open Source PHP client for the elasticsearch search engine/database. • Reference Link : http://www.elastica.io/en • To use Elastica, Download and Include Elastica in a project using PHP autoload. function __autoload_elastica ($class) { $path = str_replace('_', '/', $class); if (file_exists('/xampp/htdocs/project/Elastica/lib/' . $path . '.php')) { require_once('/xampp/htdocs/project/Elastica/lib/' . $path . '.php'); } } spl_autoload_register('__autoload_elastica'); • Connecting to ElasticSearch: On single node : $elasticaClient- = new Elastica_Client(array('host' => '192.168.0.27','port' => '9200')); • It is quite easy to start a elasticsearch cluster simply by starting multiple instances of elasticsearch on one server or on multiple servers. One of the goals of the distributed search index is availability. If one server goes down, search results should still be served. $elasticaClient- = new Elastica_Client('servers'=>array(array('host' => '192.168.0.27','port' => '9200'), array('host' => '192.168.0.27','port' => '9201')));
  • 16. • Create Index : Elastica $elasticaClient- = new Elastica_Client(array('host' => '192.168.0.27','port' => '9200')); $elasticaIndex = $elasticaClient->getIndex(‘sales'); $elasticaIndex->create( array( 'number_of_shards' => 4, 'number_of_replicas' => 1), true); • Define Mapping : $mapping = new Elastica_Type_Mapping(); $elasticaIndex = $elasticaClient- >getIndex('sales'); $elasticaType = $elasticaIndex->getType('order'); $mapping->setType($elasticaType); $mapping->setProperties(array( 'entity_id' => array('type' => 'integer'), 'increment_id' => array('type' => 'string',"index" => "not_analyzed"), ‘status' =>array('type'=>'string',"index" => "not_analyzed") )); $mapping->send();
  • 17. Elastica Add documents $elasticaClient- = new Elastica_Client(array('host' => '192.168.0.27','port' => '9200')); $elasticaIndex = $elasticaClient ->getIndex('sales'); $elasticaType = $elasticaIndex->getType('order'); // The Id of the document $id = 1; // Create a document $record = array('entity_id'=>1, ‘increment_id'=>‘100001',‘status'=>‘confirmed'); $recordDocument = new Elastica_Document($id, $record); // Add record to type $elasticaType->addDocument($ recordDocument ); // Refresh Index $elasticaType->getIndex()->refresh();
  • 18. Elastica Get Document $elasticaClient- = new Elastica_Client(array('host' => '192.168.0.27','port' => '9200')); $index = $elasticaClient->getIndex('sales'); //get index $type = $index->getType('order'); //get type $Doc = $type->getDocument($id)->getData(); //get data
  • 19. Elastica Update Document $elasticaClient- = new Elastica_Client(array('host' => '192.168.0.27','port' => '9200')); $index = $elasticaClient->getIndex('sales'); //get index $type = $index->getType('order'); //get type $id = 1; //id of document which need to be updated $newVal = 'confirmed'; //value to be updated $update = new Elastica_Script("ctx._source.status = newval", array('newval' => $newVal)); $res=$type->updateDocument($id,$update); if(!empty($res)) { $val=$res->getData(); if($val['ok']) { echo "updated"; } else { echo “value not updated"; } } else { echo “value not updated"; }
  • 20. Elastica Search Documents • The search API allows to execute a search query and get back search hits that match the query. • Search API consists following major methods: – Query String – Term – Terms – Range – Bool Query – Filter (it also contain Filter_term, Filter_Range etc) – Facets (it contain Facet_Range, Facet_Terms,Facet_Filter, Facet_Query, Facet_statistical etc.) – Query (where we can set fields for output, limit , sorting)
  • 21. Search Documents – Query String $elasticaClient = new Elastica_Client(array('host' => '192.168.0.27','port' => '9200')); $elasticaIndex = $elasticaClient->getIndex('sales'); $elasticaType = $elasticaIndex->getType('order'); $elasticaQueryString = new Elastica_Query_QueryString(); $elasticaQueryString->setQuery((string) “shipped*"); $elasticaQueryString->setFields(array(‘status')); //we can set 1 or more than 1 field in query string $elasticaQuery = new Elastica_Query(); $elasticaQuery->setQuery($elasticaQueryString); $elasticaQuery->setFields(array('increment_id','entity_id','billing_name','grand_total')); $elasticaQuery->setFrom(0); $elasticaQuery->setLimit(20); $sort = array("entity_id" => "desc"); $elasticaQuery->setSort($sort); $elasticaResultSet = $elasticaType->search($elasticaQuery); $totalResults = $ elasticaResultSet ->getTotalHits(); $elasticaResults = $elasticaResultSet ->getResults(); foreach ($elasticaResults as $elasticaResult) { print_r($elasticaResult->getData());
  • 22. Search Documents – Query Term $elasticaQueryTerm = new Elastica_Query_Term(); $elasticaQueryTerm->setTerm('entity_id',1); $elasticaQuery = new Elastica_Query(); $elasticaQuery->setQuery($elasticaQueryTerm); $elasticaQuery->setFields(array('increment_id','entity_id','billing_name','grand_total')); $elasticaQuery->setFrom(0); $elasticaQuery->setLimit(20); $sort = array("entity_id" => “asc"); $elasticaQuery->setSort($sort); $elasticaResultSet = $elasticaType->search($elasticaQuery);
  • 23. Search Documents – Query Terms $elasticaQueryTerms = new Elastica_Query_Terms(); //for query terms, you can specify 1 or more than 1 value per field $elasticaQueryTerms->setTerms('entity_id', array(1,2,3,4,5)); $elasticaQueryTerms->addTerm(6); $elasticaQuery = new Elastica_Query(); $elasticaQuery->setQuery($elasticaQueryTerms); $elasticaQuery->setFields(array('increment_id','entity_id','billing_name','grand_total')); $elasticaQuery->setFrom(0); $elasticaQuery->setLimit(20); $sort = array("entity_id" => “asc"); $elasticaQuery->setSort($sort); $elasticaResultSet = $elasticaType->search($elasticaQuery);
  • 24. Search Documents – Query Range $elasticaQueryRange = new Elastica_Query_Range(); //for range query , you can specify from, from & to or to only $elasticaQueryRange->addField('entity_id', array('from' => 10,"to"=>14)); $elasticaQuery = new Elastica_Query(); $elasticaQuery->setQuery($elasticaQueryRange); $elasticaQuery->setFields(array('increment_id','entity_id','billing_name','grand_total')); $elasticaQuery->setFrom(0); $elasticaQuery->setLimit(20); $sort = array("entity_id" => “asc"); $elasticaQuery->setSort($sort); $elasticaResultSet = $elasticaType->search($elasticaQuery);
  • 25. Search Documents – Bool Query • • The bool query maps to Lucene BooleanQuery Bool Query contains clause Occurrence – must, should, must_not $boolQuery = new Elastica_Query_Bool(); $elasticaQueryString = new Elastica_Query_QueryString(); $elasticaQueryString ->setQuery(‘shoh*'); $elasticaQueryString->setFields(array('‘billing_name, ‘shipping_name')); $boolQuery->addMust($elasticaQueryString); $elasticaQueryTerm = new Elastica_Query_Term(); $elasticaQueryTerm->setTerm('entity_id',1); $boolQuery->addMust($elasticaQueryTerm ); $elasticaQuery = new Elastica_Query(); $elasticaQuery->setQuery($boolQuery); $elasticaResultSet = $elasticaType->search($elasticaQuery);
  • 26. Search Documents – Query Filters • When doing things like facet navigation, sometimes only the hits are needed to be filtered by the chosen facet, and all the facets should continue to be calculated based on the original query. The filter element within the search request can be used to accomplish it. $elasticaQueryString = new Elastica_Query_QueryString(); $elasticaQueryString->setQuery('*'); $elasticaQueryString->setFields(array('increment_id')); $filteredQuery = new Elastica_Query_Filtered($elasticaQueryString,new Elastica_Filter_Range('created_at', array('from' => '2011-01-04 07:36:00','to' => '2013-01-04 19:36:25'))); $elasticaQuery = new Elastica_Query(); $elasticaQuery->setQuery($filteredQuery); $elasticaResultSet = $elasticaType->search($elasticaQuery);
  • 27. Elastica - Facet Terms $elasticaQuery = new Elastica_Query(); $elasticaQuery->setQuery($boolQuery); //set main query $facet = new Elastica_Facet_Terms('status Facet'); $facet->setField('status'); $facet->setOrder(‘term'); //another options are reverse_term,count,reverse_count $facet->setSize(5); $elasticaQuery->addFacet($facet); //adding facet to query $elasticaResultSet = $elasticaType->search($elasticaQuery); $facets = $ elasticaResultSet ->getFacets(); //get facets data foreach($facets as $k=>$v) { if(isset($v['terms']) && is_array($v['terms'])) { $data['facets'][$k]=$v['terms']; } }