Search in sources :

Example 1 with Article

use of com.tangtang.elasticsearchexample.domain.Article in project benchmark by seelunzi.

the class TestContreller method testSaveArticleIndex.

@RequestMapping("/add")
public void testSaveArticleIndex() {
    Author author = new Author();
    author.setId(1L);
    author.setName("tianshouzhi");
    author.setRemark("java developer");
    Tutorial tutorial = new Tutorial();
    tutorial.setId(1L);
    tutorial.setName("elastic search");
    Article article = new Article();
    article.setId(1L);
    article.setTitle("springboot integreate elasticsearch");
    article.setAbstracts("springboot integreate elasticsearch is very easy");
    article.setTutorial(tutorial);
    article.setAuthor(author);
    article.setContent("elasticsearch based on lucene," + "spring-data-elastichsearch based on elaticsearch" + ",this tutorial tell you how to integrete springboot with spring-data-elasticsearch");
    article.setPostTime(new Date());
    article.setClickCount(1L);
    articleSearchRepository.save(article);
}
Also used : Tutorial(com.tangtang.elasticsearchexample.domain.Tutorial) Article(com.tangtang.elasticsearchexample.domain.Article) Author(com.tangtang.elasticsearchexample.domain.Author) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Article

use of com.tangtang.elasticsearchexample.domain.Article in project benchmark by seelunzi.

the class TestContreller method testSearch.

@RequestMapping("/query")
public void testSearch() {
    // 搜索关键字
    String queryString = "springboot";
    QueryStringQueryBuilder builder = new QueryStringQueryBuilder(queryString);
    Iterable<Article> searchResult = articleSearchRepository.search(builder);
    Iterator<Article> iterator = searchResult.iterator();
    while (iterator.hasNext()) {
        System.out.println(iterator.next());
    }
}
Also used : Article(com.tangtang.elasticsearchexample.domain.Article) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Article (com.tangtang.elasticsearchexample.domain.Article)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Author (com.tangtang.elasticsearchexample.domain.Author)1 Tutorial (com.tangtang.elasticsearchexample.domain.Tutorial)1 Date (java.util.Date)1 QueryStringQueryBuilder (org.elasticsearch.index.query.QueryStringQueryBuilder)1