This commit is contained in:
DOHA
2016-05-28 12:39:17 +02:00
parent c76666a9b3
commit b67ecea631
9 changed files with 101 additions and 98 deletions
@@ -19,7 +19,7 @@ import java.nio.file.Paths;
@Configuration
@EnableElasticsearchRepositories(basePackages = "com.baeldung.spring.data.es.repository")
@ComponentScan(basePackages = {"com.baeldung.spring.data.es.service"})
@ComponentScan(basePackages = { "com.baeldung.spring.data.es.service" })
public class Config {
private static Logger logger = LoggerFactory.getLogger(Config.class);
@@ -29,17 +29,11 @@ public class Config {
try {
Path tmpDir = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), "elasticsearch_data");
ImmutableSettings.Builder elasticsearchSettings = ImmutableSettings.settingsBuilder()
.put("http.enabled", "false")
.put("path.data", tmpDir.toAbsolutePath().toString());
ImmutableSettings.Builder elasticsearchSettings = ImmutableSettings.settingsBuilder().put("http.enabled", "false").put("path.data", tmpDir.toAbsolutePath().toString());
logger.debug(tmpDir.toAbsolutePath().toString());
return new NodeBuilder()
.local(true)
.settings(elasticsearchSettings.build())
.node()
.client();
return new NodeBuilder().local(true).settings(elasticsearchSettings.build()).node().client();
} catch (IOException ioex) {
logger.error("Cannot create temp dir", ioex);
throw new RuntimeException();
@@ -16,12 +16,7 @@ public class Article {
@Id
private String id;
@MultiField(
mainField = @Field(type = String),
otherFields = {
@NestedField(index = not_analyzed, dotSuffix = "verbatim", type = String)
}
)
@MultiField(mainField = @Field(type = String), otherFields = { @NestedField(index = not_analyzed, dotSuffix = "verbatim", type = String) })
private String title;
@Field(type = Nested)
@@ -71,11 +66,6 @@ public class Article {
@Override
public String toString() {
return "Article{" +
"id='" + id + '\'' +
", title='" + title + '\'' +
", authors=" + authors +
", tags=" + Arrays.toString(tags) +
'}';
return "Article{" + "id='" + id + '\'' + ", title='" + title + '\'' + ", authors=" + authors + ", tags=" + Arrays.toString(tags) + '}';
}
}
@@ -21,8 +21,6 @@ public class Author {
@Override
public String toString() {
return "Author{" +
"name='" + name + '\'' +
'}';
return "Author{" + "name='" + name + '\'' + '}';
}
}
@@ -6,10 +6,16 @@ import org.springframework.data.domain.Pageable;
public interface ArticleService {
Article save(Article article);
Article findOne(String id);
Iterable<Article> findAll();
Page<Article> findByAuthorName(String name, Pageable pageable);
Page<Article> findByAuthorNameUsingCustomQuery(String name, Pageable pageable);
long count();
void delete(Article article);
}
@@ -49,6 +49,6 @@ public class ArticleServiceImpl implements ArticleService {
@Override
public void delete(Article article) {
articleRepository.delete(article);
articleRepository.delete(article);
}
}