狠狠撸

狠狠撸Share a Scribd company logo
Elastic Search Basics
Amresh Kumar Singh
What is Elastic Search?
? Elastic Search is a highly scalable, distributed,
open-source, full-text search and analytics
engine.
? Allows you to store, search, and analyze big
volumes of data quickly and in near real
time. Near RealTime (NRT) search platform. There is a slight latency
(normally one second) from the time you index a document until the time it becomes
searchable.
? Built on top of Lucene, implemented in Java
(cross platform)
FullText Search?
Basic Concepts
? Cluster (default name: elasticsearch)
? Nodes (default name: a random marvel character name)
? Index (collection of documents)
? IndexType (Mandatory. Logical partition of an index, data actually
physically resides in Index)
? Document (Basic unit of indexable info, physically resides in index,
must be assigned to a type)
? Shards (Index can be split into multiple shards, default 5, spread over
nodes. Each shard is a LUCENE index internally.
? Replica (A shard may be either Primary Shard or Replica Shard, default
replicas=1)
Elastic Search Cluster,Topology 1
3 Nodes cluster
Index A: (3 shards, 1 replica)
Index B (3 shards, 1 replica)
Elastic Search Cluster,Topology 2
Elastic SearchVs Lucene
? Elastic Search = LUCENE + RESTful Service +
High Availability & Performance + LongTerm
Persistency
RDBMSVs Elastic Search
Commands
? Starting Elastic Search
./elasticsearch --cluster.name my_cluster_name --node.name my_node_name
? Check Cluster Health
GET localhost:9200/_cat/health
? List Nodes
GET localhost:9200/_cat/nodes
? List Indices
GET localhost:9200/_cat/indices
? Create Index
PUT localhost:9200/<index name>
Commands (…contd)
? Index/Replace a document
PUT localhost:9200/<index name>/<type name>/<ID>
{
"field1" : "value1",
"field2" : "value2"
}
? Retrieve a document
GET localhost:9200/<index name>/<type name>/<ID>
? Delete an Index
DELETE localhost:9200/<index name>
? Update a Document
POST localhost:9200/<index name>/<type name>/<ID>/_update
{
"doc": { "field1": "value1", "field2": value2 }
}
Commands (…contd)
? Delete a document
DELETE localhost:9200/<index name>/<type name>/<ID>
? Batch Processing
POST localhost:9200/<index name>/<type name>/_bulk
{"index":{"_id":"<ID1>"}}
{"field1": "value1" }
{"index":{"_id":"<ID2>"}}
{"field2": "value2" }
Search API
? Elastic Search has its own JSON-style query
DSL.
? Two basic ways to send search parameters:
1.Through REST Request URI
GET localhost:9200/<index name>/_search?q=*
2.Through REST Body
POST localhost:9200/<index name>/_search
{
"query": { "match_all": {} }
}
ThankYou

More Related Content

ElasticSearch Basics

  • 2. What is Elastic Search? ? Elastic Search is a highly scalable, distributed, open-source, full-text search and analytics engine. ? Allows you to store, search, and analyze big volumes of data quickly and in near real time. Near RealTime (NRT) search platform. There is a slight latency (normally one second) from the time you index a document until the time it becomes searchable. ? Built on top of Lucene, implemented in Java (cross platform)
  • 4. Basic Concepts ? Cluster (default name: elasticsearch) ? Nodes (default name: a random marvel character name) ? Index (collection of documents) ? IndexType (Mandatory. Logical partition of an index, data actually physically resides in Index) ? Document (Basic unit of indexable info, physically resides in index, must be assigned to a type) ? Shards (Index can be split into multiple shards, default 5, spread over nodes. Each shard is a LUCENE index internally. ? Replica (A shard may be either Primary Shard or Replica Shard, default replicas=1)
  • 5. Elastic Search Cluster,Topology 1 3 Nodes cluster Index A: (3 shards, 1 replica) Index B (3 shards, 1 replica)
  • 7. Elastic SearchVs Lucene ? Elastic Search = LUCENE + RESTful Service + High Availability & Performance + LongTerm Persistency
  • 9. Commands ? Starting Elastic Search ./elasticsearch --cluster.name my_cluster_name --node.name my_node_name ? Check Cluster Health GET localhost:9200/_cat/health ? List Nodes GET localhost:9200/_cat/nodes ? List Indices GET localhost:9200/_cat/indices ? Create Index PUT localhost:9200/<index name>
  • 10. Commands (…contd) ? Index/Replace a document PUT localhost:9200/<index name>/<type name>/<ID> { "field1" : "value1", "field2" : "value2" } ? Retrieve a document GET localhost:9200/<index name>/<type name>/<ID> ? Delete an Index DELETE localhost:9200/<index name> ? Update a Document POST localhost:9200/<index name>/<type name>/<ID>/_update { "doc": { "field1": "value1", "field2": value2 } }
  • 11. Commands (…contd) ? Delete a document DELETE localhost:9200/<index name>/<type name>/<ID> ? Batch Processing POST localhost:9200/<index name>/<type name>/_bulk {"index":{"_id":"<ID1>"}} {"field1": "value1" } {"index":{"_id":"<ID2>"}} {"field2": "value2" }
  • 12. Search API ? Elastic Search has its own JSON-style query DSL. ? Two basic ways to send search parameters: 1.Through REST Request URI GET localhost:9200/<index name>/_search?q=* 2.Through REST Body POST localhost:9200/<index name>/_search { "query": { "match_all": {} } }