SlideShare a Scribd company logo
Elasticsearch. Data
management
Binary Studio Academy PRO 2016
binary-studio.com
Documents
Structure
{
"_id": "AVRZdOpTUK45DyN031IC",
"_index": "github",
"_source": {
"forks_count": 13294,
"html_url": "https://github.com/mbostock/d3",
"language": "JavaScript",
"name": "d3",
"watchers_count": 49272
},
"_type": "repos",
"_version": 1,
"found": true
}
Documents API
Create Document
Custom ID Auto-generated (UUID) ID
PUT /{index}/{type}/{id}[?op_type=create]|[/_create]
{
"field": "value",
...
}
POST /{index}/{type}
{
"field": "value",
…
}
{
"_id": "10",
"_index": "github",
"_source": {
"language": "JavaScript",
"name": "d3",
"watchers_count": 49272
},
"_type": "repos",
"_version": 1,
"found": true
}
{
"_id": "AVRZdOpTUK45DyN031IC",
"_index": "github",
"_source": {
"language": "JavaScript",
"name": "d3",
"watchers_count": 49272
},
"_type": "repos",
"_version": 1,
"found": true
}
Document Retrieval
Full Document Partial
GET /{index}/{type}/{id}
GET /github/repos/10[?pretty]
{
"_id": "10",
"_index": "github",
"_source": {
"language": "JavaScript",
"name": "d3",
"watchers_count": 49272
},
"_type": "repos",
"_version": 1,
"found": true
}
{
"_id": "AVRZdOpTUK45DyN031IC",
"_index": "github",
"_source": {
"language": "JavaScript",
"name": "d3"
},
"_type": "repos",
"_version": 1,
"found": true
}
GET
/{index}/{type}/{id}?_source[=field1,..fieldN]
GET /github/repos/10?_source=name,language
Document Presense
Document Removal
HEAD /{index}/{type}/{id}
200 || 404
DELETE /{index}/{type}/{id}
{
"_id": "AVRJ6Cm2HLfrw-ZrHWLm",
"_index": "fifa",
"_type": "players",
"_version": 2, -- incremented always
"found": true -- or false
}
Document Updates
● Documents are IMMUTABLE --> each update creates new “snapshot”
with ++_version
● Whole document update with PUT /{index}/{type}/{id} <body>
emits next action sequence:
○ Retrieve data from an old doc
○ Change it
○ Delete old doc
○ Index new (updated) doc
● Better to use update API (made this in single action)
● Updates are conflict exposed
Dealing with conflicts
5
4` 4`
4
4
o/
Concurrency causes problems :)
Pessimistic control (db): lock (row, table, record)
Optimistic control (elastic): conflict won’t occur.
Update will just fail.
PUT /{index}/{type}/{id}?version=N <body>
Next update with the same version will return 409
HTTP status
_update API
POST /{index}/{type}/{id}/_update[?retry_on_conflict=number_of_times]
{
“doc”: {
“field1”: value
“fieldN”: valueN
}
}
curl -XPOST /github/repos/2/_update -d '{"doc": {"tags": ["kernel", "c"]}}'
Bulk operations
Retrieve multiple docs (_mget)
POST /_mget
{
“docs”: [
{
“_id”: “ID”,
“_index”: “my_index”,
“_type”: ”type”
}
{...}
]
}
POST /{index}/{type}/_mget
{
“ids”: [“1”,..”N”]
}
curl -XPOST localhost:9200/github/repos/_mget -d '{"ids": [2, 3]}'
Insert multiple docs (_bulk)
action: create|index|update|delete
metadata:{“_index”:””, “_type”:””, “_id”:””}
body: {“title”: “New article title”}
curl -s -XPOST localhost:9200/_bulk --data-binary "@filename_with_newlines_format";
Data Mapping
Available data types
● Simple:
○ String: string
○ Whole number: byte , short , integer , long
○ Float: float , double
○ Boolean: boolean
○ Date: date
● Multivalue: { "tag": [ "search", "nosql" ]}
● Empty: null, [ ], [ null ]
● Nested: every nested level has type object
Single field mapping
{
"tag": {
"type": "string",
"index": "analyzed", -- analyzed | not_analyzed | no
"analyzer": "english"
}
}
Assign mapping for a type
{
"mappings": {
"repos": {
"properties": {
"name": {
"type": "string"
},
"language": {
"type": "string"
},
"watchers_count": {
"type": "long"
}
}
}
}
}
PUT /{index} <mapping>
{
"_id": "10",
"_index": "github",
"_source": {
"language": "JavaScript",
"name": "d3",
"watchers_count": 49272
},
"_type": "repos",
"_version": 1,
"found": true
}
Document Example:
Index management
Basic Index API
Create index
Delete index
DELETE /{index} || /{index1,indexN} || /_all
Update settings
To be continued ...

More Related Content

PPTX
Building Your First Application with MongoDB
KEY
CouchDB on Android
PPTX
Dev Jumpstart: Build Your First App with MongoDB
PDF
Fun Teaching MongoDB New Tricks
PDF
elasticsearch - advanced features in practice
PDF
Hd insight programming
PDF
Green dao
Building Your First Application with MongoDB
CouchDB on Android
Dev Jumpstart: Build Your First App with MongoDB
Fun Teaching MongoDB New Tricks
elasticsearch - advanced features in practice
Hd insight programming
Green dao

What's hot (19)

PDF
OrientDB
ODP
Indexed db
PDF
Elasticsearch first-steps
KEY
MongoDB
PPTX
Dev Jumpstart: Building Your First App
PDF
Doctrine for NoSQL
PDF
Doctrine and NoSQL
PDF
wtf is in Java/JDK/wtf7?
PDF
Polyglot Persistence
PDF
NoSQL - An introduction to CouchDB
PPTX
MongoDB + Java - Everything you need to know
PDF
Java development with MongoDB
PPTX
Morphia, Spring Data & Co.
PPTX
Simplifying Persistence for Java and MongoDB with Morphia
PDF
Apache CouchDB Presentation @ Sept. 2104 GTALUG Meeting
PDF
Java Persistence Frameworks for MongoDB
PDF
10gen Presents Schema Design and Data Modeling
PPTX
MongoDB - Aggregation Pipeline
PPTX
Morphia: Simplifying Persistence for Java and MongoDB
OrientDB
Indexed db
Elasticsearch first-steps
MongoDB
Dev Jumpstart: Building Your First App
Doctrine for NoSQL
Doctrine and NoSQL
wtf is in Java/JDK/wtf7?
Polyglot Persistence
NoSQL - An introduction to CouchDB
MongoDB + Java - Everything you need to know
Java development with MongoDB
Morphia, Spring Data & Co.
Simplifying Persistence for Java and MongoDB with Morphia
Apache CouchDB Presentation @ Sept. 2104 GTALUG Meeting
Java Persistence Frameworks for MongoDB
10gen Presents Schema Design and Data Modeling
MongoDB - Aggregation Pipeline
Morphia: Simplifying Persistence for Java and MongoDB
Ad

Viewers also liked (15)

PPT
Śniadanie Daje Moc
PPT
Kasuistika MUDr Ivanov 2
PPT
Kasuistika Twin Block
PDF
cv-sergio-alves-fr
DOCX
final essai
PDF
De l’usage des Options Réelles dans le secteur des Biotechs
PDF
La Economía Argentina post elecciones 2013
PPT
Kasuistika Twin Block
DOC
El cambio climático Lua
PDF
PDF
Business Governance & Environment - World Trade Organization & TRIPS
PDF
iMind Mapping خرائط العقل الإلكترونية
DOCX
CV 2015
PPTX
Lecture 8 ib 404 institutional framework for international business
Śniadanie Daje Moc
Kasuistika MUDr Ivanov 2
Kasuistika Twin Block
cv-sergio-alves-fr
final essai
De l’usage des Options Réelles dans le secteur des Biotechs
La Economía Argentina post elecciones 2013
Kasuistika Twin Block
El cambio climático Lua
Business Governance & Environment - World Trade Organization & TRIPS
iMind Mapping خرائط العقل الإلكترونية
CV 2015
Lecture 8 ib 404 institutional framework for international business
Ad

Similar to Academy PRO: Elasticsearch. Data management (20)

PDF
03. ElasticSearch : Data In, Data Out
KEY
Couchdb: No SQL? No driver? No problem
PPTX
Academy PRO: Querying Elasticsearch
PPTX
ElasticSearch AJUG 2013
KEY
Elasticsearch & "PeopleSearch"
PPTX
Elasticsearch
KEY
CouchDB : More Couch
PDF
REST Web API with MongoDB
PPTX
Elastic search intro-@lamper
PPTX
Elastic 101 - Get started
PPTX
Elasticsearch Field Data Types
PDF
Workshop: Learning Elasticsearch
PDF
Build your first MongoDB App in Ruby @ StrangeLoop 2013
PPTX
Elastic search Walkthrough
PPTX
ElasticSearch - DevNexus Atlanta - 2014
PPTX
PHP: GraphQL consistency through code generation
PDF
Elasticsearch JVM-MX Meetup April 2016
PDF
REST easy with API Platform
PDF
RESTFUL SERVICES MADE EASY: THE EVE REST API FRAMEWORK - Nicola Iarocci - Co...
PPSX
Elasticsearch - basics and beyond
03. ElasticSearch : Data In, Data Out
Couchdb: No SQL? No driver? No problem
Academy PRO: Querying Elasticsearch
ElasticSearch AJUG 2013
Elasticsearch & "PeopleSearch"
Elasticsearch
CouchDB : More Couch
REST Web API with MongoDB
Elastic search intro-@lamper
Elastic 101 - Get started
Elasticsearch Field Data Types
Workshop: Learning Elasticsearch
Build your first MongoDB App in Ruby @ StrangeLoop 2013
Elastic search Walkthrough
ElasticSearch - DevNexus Atlanta - 2014
PHP: GraphQL consistency through code generation
Elasticsearch JVM-MX Meetup April 2016
REST easy with API Platform
RESTFUL SERVICES MADE EASY: THE EVE REST API FRAMEWORK - Nicola Iarocci - Co...
Elasticsearch - basics and beyond

More from Binary Studio (20)

PPTX
Academy PRO: D3, part 3
PPTX
Academy PRO: D3, part 1
PPTX
Academy PRO: Cryptography 3
PPTX
Academy PRO: Cryptography 1
PPTX
Academy PRO: Advanced React Ecosystem. MobX
PPTX
Academy PRO: Docker. Part 4
PPTX
Academy PRO: Docker. Part 2
PPTX
Academy PRO: Docker. Part 1
PPTX
Binary Studio Academy 2017: JS team project - Orderly
PPTX
Binary Studio Academy 2017: .NET team project - Unicorn
PPTX
Academy PRO: React native - miscellaneous
PPTX
Academy PRO: React native - publish
PPTX
Academy PRO: React native - navigation
PPTX
Academy PRO: React native - building first scenes
PPTX
Academy PRO: React Native - introduction
PPTX
Academy PRO: Push notifications. Denis Beketsky
PPTX
Academy PRO: Docker. Lecture 4
PPTX
Academy PRO: Docker. Lecture 3
PPTX
Academy PRO: Docker. Lecture 2
PPTX
Academy PRO: Docker. Lecture 1
Academy PRO: D3, part 3
Academy PRO: D3, part 1
Academy PRO: Cryptography 3
Academy PRO: Cryptography 1
Academy PRO: Advanced React Ecosystem. MobX
Academy PRO: Docker. Part 4
Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 1
Binary Studio Academy 2017: JS team project - Orderly
Binary Studio Academy 2017: .NET team project - Unicorn
Academy PRO: React native - miscellaneous
Academy PRO: React native - publish
Academy PRO: React native - navigation
Academy PRO: React native - building first scenes
Academy PRO: React Native - introduction
Academy PRO: Push notifications. Denis Beketsky
Academy PRO: Docker. Lecture 4
Academy PRO: Docker. Lecture 3
Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 1

Recently uploaded (20)

PDF
top salesforce developer skills in 2025.pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
medical staffing services at VALiNTRY
PDF
System and Network Administration Chapter 2
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Introduction to Artificial Intelligence
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Digital Strategies for Manufacturing Companies
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Nekopoi APK 2025 free lastest update
PDF
System and Network Administraation Chapter 3
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
top salesforce developer skills in 2025.pdf
Reimagine Home Health with the Power of Agentic AI​
medical staffing services at VALiNTRY
System and Network Administration Chapter 2
wealthsignaloriginal-com-DS-text-... (1).pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Design an Analysis of Algorithms II-SECS-1021-03
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Introduction to Artificial Intelligence
Design an Analysis of Algorithms I-SECS-1021-03
Digital Strategies for Manufacturing Companies
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Navsoft: AI-Powered Business Solutions & Custom Software Development
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
VVF-Customer-Presentation2025-Ver1.9.pptx
Nekopoi APK 2025 free lastest update
System and Network Administraation Chapter 3
2025 Textile ERP Trends: SAP, Odoo & Oracle
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...

Academy PRO: Elasticsearch. Data management

  • 1. Elasticsearch. Data management Binary Studio Academy PRO 2016 binary-studio.com
  • 3. Structure { "_id": "AVRZdOpTUK45DyN031IC", "_index": "github", "_source": { "forks_count": 13294, "html_url": "https://github.com/mbostock/d3", "language": "JavaScript", "name": "d3", "watchers_count": 49272 }, "_type": "repos", "_version": 1, "found": true }
  • 5. Create Document Custom ID Auto-generated (UUID) ID PUT /{index}/{type}/{id}[?op_type=create]|[/_create] { "field": "value", ... } POST /{index}/{type} { "field": "value", … } { "_id": "10", "_index": "github", "_source": { "language": "JavaScript", "name": "d3", "watchers_count": 49272 }, "_type": "repos", "_version": 1, "found": true } { "_id": "AVRZdOpTUK45DyN031IC", "_index": "github", "_source": { "language": "JavaScript", "name": "d3", "watchers_count": 49272 }, "_type": "repos", "_version": 1, "found": true }
  • 6. Document Retrieval Full Document Partial GET /{index}/{type}/{id} GET /github/repos/10[?pretty] { "_id": "10", "_index": "github", "_source": { "language": "JavaScript", "name": "d3", "watchers_count": 49272 }, "_type": "repos", "_version": 1, "found": true } { "_id": "AVRZdOpTUK45DyN031IC", "_index": "github", "_source": { "language": "JavaScript", "name": "d3" }, "_type": "repos", "_version": 1, "found": true } GET /{index}/{type}/{id}?_source[=field1,..fieldN] GET /github/repos/10?_source=name,language
  • 7. Document Presense Document Removal HEAD /{index}/{type}/{id} 200 || 404 DELETE /{index}/{type}/{id} { "_id": "AVRJ6Cm2HLfrw-ZrHWLm", "_index": "fifa", "_type": "players", "_version": 2, -- incremented always "found": true -- or false }
  • 8. Document Updates ● Documents are IMMUTABLE --> each update creates new “snapshot” with ++_version ● Whole document update with PUT /{index}/{type}/{id} <body> emits next action sequence: ○ Retrieve data from an old doc ○ Change it ○ Delete old doc ○ Index new (updated) doc ● Better to use update API (made this in single action) ● Updates are conflict exposed
  • 9. Dealing with conflicts 5 4` 4` 4 4 o/ Concurrency causes problems :) Pessimistic control (db): lock (row, table, record) Optimistic control (elastic): conflict won’t occur. Update will just fail. PUT /{index}/{type}/{id}?version=N <body> Next update with the same version will return 409 HTTP status
  • 10. _update API POST /{index}/{type}/{id}/_update[?retry_on_conflict=number_of_times] { “doc”: { “field1”: value “fieldN”: valueN } } curl -XPOST /github/repos/2/_update -d '{"doc": {"tags": ["kernel", "c"]}}'
  • 12. Retrieve multiple docs (_mget) POST /_mget { “docs”: [ { “_id”: “ID”, “_index”: “my_index”, “_type”: ”type” } {...} ] } POST /{index}/{type}/_mget { “ids”: [“1”,..”N”] } curl -XPOST localhost:9200/github/repos/_mget -d '{"ids": [2, 3]}'
  • 13. Insert multiple docs (_bulk) action: create|index|update|delete metadata:{“_index”:””, “_type”:””, “_id”:””} body: {“title”: “New article title”} curl -s -XPOST localhost:9200/_bulk --data-binary "@filename_with_newlines_format";
  • 15. Available data types ● Simple: ○ String: string ○ Whole number: byte , short , integer , long ○ Float: float , double ○ Boolean: boolean ○ Date: date ● Multivalue: { "tag": [ "search", "nosql" ]} ● Empty: null, [ ], [ null ] ● Nested: every nested level has type object
  • 16. Single field mapping { "tag": { "type": "string", "index": "analyzed", -- analyzed | not_analyzed | no "analyzer": "english" } }
  • 17. Assign mapping for a type { "mappings": { "repos": { "properties": { "name": { "type": "string" }, "language": { "type": "string" }, "watchers_count": { "type": "long" } } } } } PUT /{index} <mapping> { "_id": "10", "_index": "github", "_source": { "language": "JavaScript", "name": "d3", "watchers_count": 49272 }, "_type": "repos", "_version": 1, "found": true } Document Example:
  • 19. Basic Index API Create index Delete index DELETE /{index} || /{index1,indexN} || /_all Update settings