Search in sources :

Example 1 with Commodity

use of com.example.esdemo.dto.Commodity in project demo by breeze0630.

the class CjsElasticsearchExampleApplicationTests method testInsert.

@Test
public void testInsert() {
    Commodity commodity = new Commodity();
    commodity.setSkuId("1501009001");
    commodity.setName("原味切片面包(10片装)");
    commodity.setCategory("101");
    commodity.setPrice(880);
    commodity.setBrand("良品铺子");
    commodity.setStock(1);
    commodityService.save(commodity);
    commodity = new Commodity();
    commodity.setSkuId("1501009002");
    commodity.setName("原味切片面包(6片装)");
    commodity.setCategory("101");
    commodity.setPrice(680);
    commodity.setBrand("良品铺子");
    commodity.setStock(2);
    commodityService.save(commodity);
    commodity = new Commodity();
    commodity.setSkuId("1501009004");
    commodity.setName("元气吐司850g");
    commodity.setCategory("101");
    commodity.setPrice(120);
    commodity.setBrand("百草味");
    commodity.setStock(3);
    commodityService.save(commodity);
}
Also used : Commodity(com.example.esdemo.dto.Commodity) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 2 with Commodity

use of com.example.esdemo.dto.Commodity in project demo by breeze0630.

the class CjsElasticsearchExampleApplicationTests method testDelete.

@Test
public void testDelete() {
    Commodity commodity = new Commodity();
    commodity.setSkuId("1501009002");
    commodityService.delete(commodity);
}
Also used : Commodity(com.example.esdemo.dto.Commodity) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 3 with Commodity

use of com.example.esdemo.dto.Commodity in project demo by breeze0630.

the class CjsElasticsearchExampleApplicationTests method testDeleteAll.

@Test
public void testDeleteAll() {
    Iterable<Commodity> iterable = commodityService.getAll();
    for (Commodity commodity : iterable) {
        commodityService.delete(commodity);
    }
    Iterable<Commodity> iterable2 = commodityService.getAll();
    if (iterable2 == null) {
        System.out.println("success");
    }
}
Also used : Commodity(com.example.esdemo.dto.Commodity) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 4 with Commodity

use of com.example.esdemo.dto.Commodity in project demo by breeze0630.

the class ElasticsearchTemplateTest method testQuery.

@Test
public void testQuery() {
    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(QueryBuilders.matchQuery("name", "吐司")).build();
    List<Commodity> list = elasticsearchTemplate.queryForList(searchQuery, Commodity.class);
    System.out.println(list);
}
Also used : SearchQuery(org.springframework.data.elasticsearch.core.query.SearchQuery) Commodity(com.example.esdemo.dto.Commodity) NativeSearchQueryBuilder(org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with Commodity

use of com.example.esdemo.dto.Commodity in project demo by breeze0630.

the class CommodityServiceImpl method getByName.

@Override
public List<Commodity> getByName(String name) {
    List<Commodity> list = new ArrayList<>();
    MatchQueryBuilder matchQueryBuilder = new MatchQueryBuilder("name", name);
    Iterable<Commodity> iterable = commodityRepository.search(matchQueryBuilder);
    iterable.forEach(e -> list.add(e));
    return list;
}
Also used : Commodity(com.example.esdemo.dto.Commodity) ArrayList(java.util.ArrayList) MatchQueryBuilder(org.elasticsearch.index.query.MatchQueryBuilder)

Aggregations

Commodity (com.example.esdemo.dto.Commodity)6 Test (org.junit.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 ArrayList (java.util.ArrayList)1 MatchQueryBuilder (org.elasticsearch.index.query.MatchQueryBuilder)1 IndexQuery (org.springframework.data.elasticsearch.core.query.IndexQuery)1 IndexQueryBuilder (org.springframework.data.elasticsearch.core.query.IndexQueryBuilder)1 NativeSearchQueryBuilder (org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder)1 SearchQuery (org.springframework.data.elasticsearch.core.query.SearchQuery)1