SlideShare a Scribd company logo
und die Java-Welt
Florian Hopf
@fhopf
Elasticsearch?
„Elasticsearch is a distributed,
open source search and
analytics engine, designed for
horizontal scalability,
reliability, and easy
management.“
Elasticsearch?
„Elasticsearch is a distributed,
open source search and
analytics engine, designed for
horizontal scalability,
reliability, and easy
management.“
Elasticsearch?
Installation
# download archive
wget https://download.elastic.co/elasticsearch
/elasticsearch/elasticsearch-1.7.2.zip
# zip is for windows and linux
unzip elasticsearch-1.7.2.zip
# on windows: elasticsearch.bat
elasticsearch-1.7.2/bin/elasticsearch
Zugriff per HTTP
curl -XGET "http://localhost:9200"
{
"status": 200,
"name": "Ultron",
"cluster_name": "elasticsearch",
"version": {
"number" : "1.7.2",
"build_hash" : "e43676b1385b8125...",
"build_timestamp" : "2015-09-14T09:49:53Z",
"build_snapshot" : false,
"lucene_version" : "4.10.4"
},
"tagline": "You Know, for Search"
}
Indizierung
curl -XPOST "http://localhost:9200/library/book" -d'
{
"title": "Elasticsearch in Action",
"author": [ "Radu Gheorghe",
"Matthew Lee Hinman",
"Roy Russo" ],
"published": "2015-06-30T00:00:00.000Z",
"publisher": {
"name": "Manning",
"country": "USA"
}
}'
Suche
curl -XPOST "http://localhost:9200/library/book/_search
?q=elasticsearch"
{
[...]
"hits": {
"hits": [
{
"_index": "library",
"_type": "book",
"_source": {
"title": "Elasticsearch in Action",
[...]
Suche per Query DSL
curl -XPOST "http://localhost:9200/library/book/_search"
-d'
{
"query": {
"filtered": {
"query": {
"match": {
"title": "elasticsearch"
}
},
"filter": {
"term": {
"publisher.name": "manning"
}
}
}
}
}'
Recap
●
Auf Java basierender Suchserver
●
HTTP und JSON
●
Suche und Filterung über Query-DSL
●
Facettierung über Aggregations
●
Highlighting, Suggestions, ...
Elasticsearch?
„Elasticsearch is a distributed,
open source search and
analytics engine, designed for
horizontal scalability,
reliability, and easy
management.“
Verteilung
Verteilung
Verteilung
Suche im Cluster
Suche im Cluster
Recap
●
Knoten können Cluster bilden
●
Datenverteilung durch Sharding
●
Replicas zur Lastverteilung und
Ausfallsicherheit
●
Verteilte Suche
●
Cluster-Zustand auf jedem Knoten
Standard-Client
Java!
dependencies {
compile group: 'org.elasticsearch',
name: 'elasticsearch',
version: '1.7.2'
}
Java!
TransportAddress address =
new InetSocketTransportAddress("localhost", 9300);
Client client = new TransportClient().
addTransportAddress(address);
Suche per Query DSL
curl -XPOST "http://localhost:9200/library/book/_search"
-d'
{
"query": {
"filtered": {
"query": {
"match": {
"title": "elasticsearch"
}
},
"filter": {
"term": {
"publisher.name": "manning"
}
}
}
}
}'
Suche über Java-Client
SearchResponse searchResponse = client
.prepareSearch("library")
.setQuery(filteredQuery(
matchQuery("title", "elasticsearch"),
termFilter("publisher.name", "manning")))
.execute().actionGet();
assertEquals(1, searchResponse.getHits().getTotalHits());
SearchHit hit = searchResponse.getHits().getAt(0);
assertEquals("Elasticsearch in Action",
hit.getSource().get("title"));
Indizierung über Java-Client
XContentBuilder jsonBuilder = jsonBuilder()
.startObject()
.field("title", "Elasticsearch")
.field("author", "Florian Hopf")
.startObject("publisher")
.field("name", "dpunkt")
.endObject()
.endObject();
client.prepareIndex("library", "book")
.setSource(jsonBuilder)
.execute().actionGet();
Indizierung über Java-Client
Transport-Client
●
Verbindet sich mit bestehendem Cluster
TransportAddress address =
new InetSocketTransportAddress("localhost", 9300);
Client client = new TransportClient().
addTransportAddress(address);
Transport-Client
Node-Client
Node node = nodeBuilder().client(true).node();
Client client = node.client();
Node-Client
●
Startet eigenen Knoten
●
Anwendung wird Teil des Clusters
Node node = nodeBuilder().client(true).node();
Client client = node.client();
Node-Client
Standard-Client
●
Volle API-Unterstützung
●
Effiziente Kommunikation
●
Node-Client
●
Cluster-State spart unnötige Hops
Standard-Client Gotchas
●
Elasticsearch-Version Client == Server
●
Node-Client
●
Bei Start und Stop wird Cluster-State übertragen
●
Speicherverbrauch
●
Elasticsearch-Dependency
Jest – Http Client
Jest
Jest
dependencies {
compile group: 'io.searchbox',
name: 'jest',
Version: '0.1.6'
}
Client
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(new HttpClientConfig
.Builder("http://localhost:9200")
.multiThreaded(true)
.build());
JestClient client = factory.getObject();
Suche mit Jest
String query = jsonStringThatMagicallyAppears;
Search search = new Search.Builder(query)
.addIndex("library")
.build();
SearchResult result = client.execute(search);
assertEquals(Integer.valueOf(1), result.getTotal());
Suche mit Jest
JsonObject jsonObject = result.getJsonObject();
JsonObject hitsObj = jsonObject.getAsJsonObject("hits");
JsonArray hits = hitsObj.getAsJsonArray("hits");
JsonObject hit = hits.get(0).getAsJsonObject();
// ... more boring code
Suche mit Jest
public class Book {
private String title;
private List<String> author;
private Publisher publisher;
public Publisher getPublisher() {
return publisher;
}
public void setPublisher(Publisher publisher) {
this.publisher = publisher;
}
// more code
}
Suche mit Jest
Book book = result.getFirstHit(Book.class).source;
assertEquals("Elasticsearch in Action", book.getTitle());
Jest
●
Alternative HTTP-Implementierung
●
Queries als String oder per Elasticsearch-
Builder
●
Indizieren und Suchen per Java-Beans
Spring Data Elasticsearch
Spring Data
●
Abstraktionen für Data-Stores
●
Spezialitäten bleiben erhalten
●
Dynamische Repository-Implementierung
●
Populäre Implementierungen
●
Spring Data JPA
●
Spring Data MongoDB
Dependency
dependencies {
compile group: 'org.springframework.data',
name: 'spring-data-elasticsearch',
version: '1.2.0.RELEASE'
}
Entity
@Document(
indexName = "library",
type = "book")
public class Book {
private String id;
private String title;
private List<String> author;
private Publisher publisher;
// more code
}
Repository
public interface BookRepository
extends ElasticsearchCrudRepository<Book, String> {
public Iterable<Book> findByTitle(String title);
}
Configuration
<elasticsearch:node-client id="client" />
<bean name="elasticsearchTemplate"
class="o.s.d.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client"/>
</bean>
<elasticsearch:repositories
base-package="de.fhopf.elasticsearch.springdata" />
Indexing
Book book = new Book();
book.setTitle("Elasticsearch");
book.setAuthor(Arrays.asList("Florian Hopf"));
book.setPublisher(new Publisher("dpunkt"));
repository.save(book);
Searching
Iterable<Book> books = repository.findAll();
books = repository.findByTitle("Elasticsearch");
Recap
●
Abstraktion über Elasticsearch
●
Entity-Beans
●
Dynamische Repository-Implementierung
●
Junges Projekt
Recap
●
Standard-Client
●
Node- oder Transport-Client
●
Jest
●
Http-Client mit Java-Bean-Unterstützung
●
Spring-Data-Elasticsearch
●
Annotationzentrierte Konfiguration, dynamische
Repository-Implementierungen
JVM?
●
Clojure: Elastisch
●
Standard-Client oder HTTP
●
Groovy: elasticsearch-groovy
●
Standard-Client, Closure-Unterstützung
●
Scala: große Auswahl, z.B. elastic4s
●
Standard-Client, Type-Safety
Links
●
https://www.found.no/foundation/java-
clients-for-elasticsearch/
●
http://elastic.co
●
https://github.com/searchbox-io/Jest
●
https://github.com/spring-projects/spring-
data-elasticsearch
●
http://blog.florian-hopf.de
Weitere Infos

More Related Content

PDF
Java clients for elasticsearch
PDF
Node.js 與 google cloud storage
PPTX
Elasticsearch 설치 및 기본 활용
PDF
Journée DevOps : Des dashboards pour tous avec ElasticSearch, Logstash et Kibana
PPTX
Webinar: Architecting Secure and Compliant Applications with MongoDB
PDF
Null Bachaav - May 07 Attack Monitoring workshop.
PDF
Caching. api. http 1.1
PDF
Web前端性能优化 2014
Java clients for elasticsearch
Node.js 與 google cloud storage
Elasticsearch 설치 및 기본 활용
Journée DevOps : Des dashboards pour tous avec ElasticSearch, Logstash et Kibana
Webinar: Architecting Secure and Compliant Applications with MongoDB
Null Bachaav - May 07 Attack Monitoring workshop.
Caching. api. http 1.1
Web前端性能优化 2014

What's hot (20)

PDF
Debugging and Testing ES Systems
PPTX
Elk stack
PDF
Unity Makes Strength
PDF
Apache CouchDB talk at Ontario GNU Linux Fest
PPTX
PPT
How ElasticSearch lives in my DevOps life
PPTX
DevOps Fest 2019. Сергей Марченко. Terraform: a novel about modules, provider...
PPT
Using npm to Manage Your Projects for Fun and Profit - USEFUL INFO IN NOTES!
PDF
Got Logs? Get Answers with Elasticsearch ELK - PuppetConf 2014
PPTX
Getting started with Elasticsearch and .NET
PDF
LogStash in action
PDF
ElasticSearch
PDF
2020-02-20 - HashiTalks 2020 - HashiCorp Vault configuration as code via Hash...
ODP
CONFidence 2014: Kiss, Zagon, Sseller: Scaling security
PPT
Node.js
PPTX
Architecting Secure and Compliant Applications with MongoDB
PDF
Machine Learning in a Twitter ETL using ELK
PDF
[NodeConf.eu 2014] Scaling AB Testing on Netflix.com with Node.js
PPTX
What I learned from FluentConf and then some
PPTX
Back to Basics Spanish 4 Introduction to sharding
Debugging and Testing ES Systems
Elk stack
Unity Makes Strength
Apache CouchDB talk at Ontario GNU Linux Fest
How ElasticSearch lives in my DevOps life
DevOps Fest 2019. Сергей Марченко. Terraform: a novel about modules, provider...
Using npm to Manage Your Projects for Fun and Profit - USEFUL INFO IN NOTES!
Got Logs? Get Answers with Elasticsearch ELK - PuppetConf 2014
Getting started with Elasticsearch and .NET
LogStash in action
ElasticSearch
2020-02-20 - HashiTalks 2020 - HashiCorp Vault configuration as code via Hash...
CONFidence 2014: Kiss, Zagon, Sseller: Scaling security
Node.js
Architecting Secure and Compliant Applications with MongoDB
Machine Learning in a Twitter ETL using ELK
[NodeConf.eu 2014] Scaling AB Testing on Netflix.com with Node.js
What I learned from FluentConf and then some
Back to Basics Spanish 4 Introduction to sharding
Ad

Viewers also liked (17)

PPTX
Oliver fuken y cristian
PDF
Taller alcohol
PDF
Noa Noa Journal Autumn 2012
PDF
Tratamiento de aguas
PPTX
Bof Process
DOCX
Value-Inspired Testing - renovating Risk-Based Testing, & innovating with Eme...
PPT
PPTX
Can the Internet Change Bangladesh
PPTX
Allocative Efficiency in Individual's Life
PDF
โครงร่างคอม
PDF
Andrea Sharfin Friedenson - How to Get Reporters to Cover Your Startup
PPTX
PDF
Sekilas tentang panas bumi
PPTX
Ethics in om final-group-1
PDF
Customer Acquisition 101
PPT
Creating, Sharing, Reflecting - Oh, The Places You'll Go!
PPTX
Oliver fuken y cristian
Taller alcohol
Noa Noa Journal Autumn 2012
Tratamiento de aguas
Bof Process
Value-Inspired Testing - renovating Risk-Based Testing, & innovating with Eme...
Can the Internet Change Bangladesh
Allocative Efficiency in Individual's Life
โครงร่างคอม
Andrea Sharfin Friedenson - How to Get Reporters to Cover Your Startup
Sekilas tentang panas bumi
Ethics in om final-group-1
Customer Acquisition 101
Creating, Sharing, Reflecting - Oh, The Places You'll Go!
Ad

Similar to Elasticsearch und die Java-Welt (20)

ODP
Groovy & Grails eXchange 2012 vert.x presentation
PPT
Exploring Node.jS
PPTX
Developing your first application using FIWARE
PDF
Node.js 1, 2, 3
PDF
DevOps &lt;3 node.js
PPTX
NodeJS
PPTX
introduction to node.js
PPTX
Fully Automate Application Delivery with Puppet and F5 - PuppetConf 2014
PPTX
Event-driven IO server-side JavaScript environment based on V8 Engine
PPTX
Attack monitoring using ElasticSearch Logstash and Kibana
PDF
Infrastructure as Code: Manage your Architecture with Git
PDF
Monitoring Docker at Scale - Docker San Francisco Meetup - August 11, 2015
PDF
Digital Forensics and Incident Response in The Cloud
PDF
FIWARE Wednesday Webinars - Short Term History within Smart Systems
PDF
how to use openstack api
PDF
Infrastructure as Code: Manage your Architecture with Git
KEY
Writing robust Node.js applications
PPTX
Introduction to kubernetes
PDF
Original slides from Ryan Dahl's NodeJs intro talk
PPTX
Deploying Cloud Native Red Team Infrastructure with Kubernetes, Istio and Envoy
Groovy & Grails eXchange 2012 vert.x presentation
Exploring Node.jS
Developing your first application using FIWARE
Node.js 1, 2, 3
DevOps &lt;3 node.js
NodeJS
introduction to node.js
Fully Automate Application Delivery with Puppet and F5 - PuppetConf 2014
Event-driven IO server-side JavaScript environment based on V8 Engine
Attack monitoring using ElasticSearch Logstash and Kibana
Infrastructure as Code: Manage your Architecture with Git
Monitoring Docker at Scale - Docker San Francisco Meetup - August 11, 2015
Digital Forensics and Incident Response in The Cloud
FIWARE Wednesday Webinars - Short Term History within Smart Systems
how to use openstack api
Infrastructure as Code: Manage your Architecture with Git
Writing robust Node.js applications
Introduction to kubernetes
Original slides from Ryan Dahl's NodeJs intro talk
Deploying Cloud Native Red Team Infrastructure with Kubernetes, Istio and Envoy

More from Florian Hopf (13)

ODP
Modern Java Features
PDF
Einführung in Elasticsearch
PDF
Introduction to elasticsearch
PDF
Einfuehrung in Elasticsearch
PDF
Data modeling for Elasticsearch
PDF
Einführung in Elasticsearch
PDF
Anwendungsfälle für Elasticsearch JAX 2015
PDF
Anwendungsfälle für Elasticsearch JavaLand 2015
PDF
Anwendungsfaelle für Elasticsearch
PDF
Search Evolution - Von Lucene zu Solr und ElasticSearch (Majug 20.06.2013)
PDF
Search Evolution - Von Lucene zu Solr und ElasticSearch
PDF
Akka Presentation Schule@synyx
PDF
Lucene Solr talk at Java User Group Karlsruhe
Modern Java Features
Einführung in Elasticsearch
Introduction to elasticsearch
Einfuehrung in Elasticsearch
Data modeling for Elasticsearch
Einführung in Elasticsearch
Anwendungsfälle für Elasticsearch JAX 2015
Anwendungsfälle für Elasticsearch JavaLand 2015
Anwendungsfaelle für Elasticsearch
Search Evolution - Von Lucene zu Solr und ElasticSearch (Majug 20.06.2013)
Search Evolution - Von Lucene zu Solr und ElasticSearch
Akka Presentation Schule@synyx
Lucene Solr talk at Java User Group Karlsruhe

Recently uploaded (20)

PDF
Understanding Forklifts - TECH EHS Solution
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
top salesforce developer skills in 2025.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Transform Your Business with a Software ERP System
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPT
Introduction Database Management System for Course Database
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Nekopoi APK 2025 free lastest update
PPTX
Operating system designcfffgfgggggggvggggggggg
Understanding Forklifts - TECH EHS Solution
How to Migrate SBCGlobal Email to Yahoo Easily
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Design an Analysis of Algorithms II-SECS-1021-03
Softaken Excel to vCard Converter Software.pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PTS Company Brochure 2025 (1).pdf.......
top salesforce developer skills in 2025.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Transform Your Business with a Software ERP System
Which alternative to Crystal Reports is best for small or large businesses.pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
Introduction Database Management System for Course Database
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Design an Analysis of Algorithms I-SECS-1021-03
How to Choose the Right IT Partner for Your Business in Malaysia
Nekopoi APK 2025 free lastest update
Operating system designcfffgfgggggggvggggggggg

Elasticsearch und die Java-Welt