diff --git a/persistence-modules/elasticsearch/pom.xml b/persistence-modules/elasticsearch/pom.xml index 7027f70900..ceed88aa24 100644 --- a/persistence-modules/elasticsearch/pom.xml +++ b/persistence-modules/elasticsearch/pom.xml @@ -2,18 +2,18 @@ 4.0.0 - com.baeldung.jest - jest-demo + com.baeldung + elasticsearch 0.0.1-SNAPSHOT - jest-demo - Demo project for Jest Client for Elasticsearch + elasticsearch + Demo project for Java Elasticsearch libraries - - - 8 - 1.8 - 1.8 - + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + ../../ + diff --git a/persistence-modules/elasticsearch/src/main/java/com/baeldung/jest/Employee.java b/persistence-modules/elasticsearch/src/main/java/com/baeldung/jest/Employee.java index 5a2c1a534f..6f28a42a9c 100644 --- a/persistence-modules/elasticsearch/src/main/java/com/baeldung/jest/Employee.java +++ b/persistence-modules/elasticsearch/src/main/java/com/baeldung/jest/Employee.java @@ -6,7 +6,7 @@ public class Employee { String name; String title; List skills; - int years_of_service; + int yearsOfService; public String getName() { return name; @@ -32,11 +32,11 @@ public class Employee { this.skills = skills; } - public int getYears_of_service() { - return years_of_service; + public int getYearsOfService() { + return yearsOfService; } - public void setYears_of_service(int years_of_service) { - this.years_of_service = years_of_service; + public void setYearsOfService(int yearsOfService) { + this.yearsOfService = yearsOfService; } } diff --git a/persistence-modules/elasticsearch/src/main/java/com/baeldung/jest/JestDemoApplication.java b/persistence-modules/elasticsearch/src/main/java/com/baeldung/jest/JestDemoApplication.java index e4c8ef51be..91e499da2e 100644 --- a/persistence-modules/elasticsearch/src/main/java/com/baeldung/jest/JestDemoApplication.java +++ b/persistence-modules/elasticsearch/src/main/java/com/baeldung/jest/JestDemoApplication.java @@ -2,8 +2,6 @@ package com.baeldung.jest; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; import io.searchbox.client.JestClient; import io.searchbox.client.JestClientFactory; import io.searchbox.client.JestResult; @@ -15,8 +13,6 @@ import io.searchbox.indices.IndicesExists; import io.searchbox.indices.aliases.AddAliasMapping; import io.searchbox.indices.aliases.ModifyAliases; import io.searchbox.indices.aliases.RemoveAliasMapping; -import io.searchbox.indices.mapping.PutMapping; -import io.searchbox.indices.settings.GetSettings; import java.io.IOException; import java.util.*; @@ -50,20 +46,27 @@ public class JestDemoApplication { "e") .build()) .build()); - jestClient.execute(new ModifyAliases.Builder( + JestResult jestResult = jestClient.execute(new ModifyAliases.Builder( new RemoveAliasMapping.Builder( "employees", "e") .build()) .build()); + if(jestResult.isSucceeded()) { + System.out.println("Success!"); + } + else { + System.out.println(jestResult.getErrorMessage()); + } + // Sample JSON for indexing // { // "name": "Michael Pratt", // "title": "Java Developer", // "skills": ["java", "spring", "elasticsearch"], - // "years_of_service": 2 + // "yearsOfService": 2 // } // Index a document from String @@ -71,7 +74,7 @@ public class JestDemoApplication { JsonNode employeeJsonNode = mapper.createObjectNode() .put("name", "Michael Pratt") .put("title", "Java Developer") - .put("years_of_service", 2) + .put("yearsOfService", 2) .set("skills", mapper.createArrayNode() .add("java") .add("spring") @@ -82,7 +85,7 @@ public class JestDemoApplication { Map employeeHashMap = new LinkedHashMap<>(); employeeHashMap.put("name", "Michael Pratt"); employeeHashMap.put("title", "Java Developer"); - employeeHashMap.put("years_of_service", 2); + employeeHashMap.put("yearsOfService", 2); employeeHashMap.put("skills", Arrays.asList("java", "spring", "elasticsearch")); jestClient.execute(new Index.Builder(employeeHashMap).index("employees").build()); @@ -90,7 +93,7 @@ public class JestDemoApplication { Employee employee = new Employee(); employee.setName("Michael Pratt"); employee.setTitle("Java Developer"); - employee.setYears_of_service(2); + employee.setYearsOfService(2); employee.setSkills(Arrays.asList("java", "spring", "elasticsearch")); jestClient.execute(new Index.Builder(employee).index("employees").build()); @@ -116,7 +119,7 @@ public class JestDemoApplication { }); // Update document - employee.setYears_of_service(3); + employee.setYearsOfService(3); jestClient.execute(new Update.Builder(employee).index("employees").id("1").build()); // Delete documents @@ -126,13 +129,13 @@ public class JestDemoApplication { Employee employeeObject1 = new Employee(); employee.setName("John Smith"); employee.setTitle("Python Developer"); - employee.setYears_of_service(10); + employee.setYearsOfService(10); employee.setSkills(Arrays.asList("python")); Employee employeeObject2 = new Employee(); employee.setName("Kate Smith"); employee.setTitle("Senior JavaScript Developer"); - employee.setYears_of_service(10); + employee.setYearsOfService(10); employee.setSkills(Arrays.asList("javascript", "angular")); jestClient.execute(new Bulk.Builder().defaultIndex("employees") @@ -144,7 +147,7 @@ public class JestDemoApplication { Employee employeeObject3 = new Employee(); employee.setName("Jane Doe"); employee.setTitle("Manager"); - employee.setYears_of_service(20); + employee.setYearsOfService(20); employee.setSkills(Arrays.asList("managing")); jestClient.executeAsync( new Index.Builder(employeeObject3).build(), new JestResultHandler() { diff --git a/persistence-modules/elasticsearch/src/main/resources/application.properties b/persistence-modules/elasticsearch/src/main/resources/application.properties deleted file mode 100644 index 8b13789179..0000000000 --- a/persistence-modules/elasticsearch/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -