Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🌐 This application illustrates and demonstrates use of ElasticSearch Java API in the backend

Notifications You must be signed in to change notification settings

giangithud/ElasticSearch

Repository files navigation

Build Status "Docker Pulls Coverage Status Analytics

Illustration and demonstration use of ElasticSearch

This repository illustrates and demonstrates the use of ElasticSearch Java API with most up to date version of ElasticSearch which provides Java High Level REST Client. If you want to see the sample of the old version, please visit the oldVersion branch.

How to Use Java High Level REST Client in the backend?

The client added in version 6.0.0-beta1 and it works on top of the Java low level rest client.

Initialization

RetHighLevelClient(RestClient.builder(new HttpHost(props.getRestClient().getHostname(),
 props.getRestClient().getPort(), props.getRestClient().getScheme())));

Creating an index

IndexRequest request = new IndexRequest(props.getIndex().getName(), props.getIndex().getType());
request.source(gson.toJson(document), XContentType.JSON);
IndexResponse response = client.index(request);

Using SearchSourceBuilder and showing search results

sourceBuilder.query(builder);
SearchRequest searchRequest = getSearchRequest();
SearchResponse searchResponse = client.search(searchRequest);
SearchHits hits = searchResponse.getHits();
SearchHit[] searchHits = hits.getHits();
for (SearchHit hit : searchHits) {
 Document doc = gson.fromJson(hit.getSourceAsString(), Document.class);
 doc.setId(hit.getId());
 result.add(doc);
}

Using wildcard query

QueryBuilders.wildcardQuery("_all", "*" + query.toLowerCase() + "*")

Deleting a document

DeleteRequest deleteRequest = new DeleteRequest(props.getIndex().getName(), props.getIndex().getType(), id);

How to run?

mvn spring-boot:run

How to run with Docker?

docker run -d --name elasticsearch -p 8080:8080 hakdogan/elasticsearch:newVersion

About

🌐 This application illustrates and demonstrates use of ElasticSearch Java API in the backend

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 62.9%
  • HTML 18.9%
  • JavaScript 17.3%
  • Shell 0.9%

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /