Search in sources :

Example 1 with UserEntity

use of com.javayh.elaticsearh.docment.UserEntity in project IT-Demo by yanghaiji.

the class EsTempWeb method agg.

@GetMapping("/agg")
public SearchHits<UserEntity> agg() {
    // 构建查询条件
    NativeSearchQuery nativeSearchQuery = new NativeSearchQueryBuilder().addAggregation(AggregationBuilders.terms("titles").field("title.keyword")).addAggregation(AggregationBuilders.sum("price sum").field("price")).build();
    SearchHits<UserEntity> search = elasticsearchTemplate.search(nativeSearchQuery, UserEntity.class);
    return search;
}
Also used : NativeSearchQueryBuilder(org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder) UserEntity(com.javayh.elaticsearh.docment.UserEntity) NativeSearchQuery(org.springframework.data.elasticsearch.core.query.NativeSearchQuery)

Example 2 with UserEntity

use of com.javayh.elaticsearh.docment.UserEntity in project IT-Demo by yanghaiji.

the class EsTempWeb method filter.

@GetMapping("/filter")
public SearchHits<UserEntity> filter() {
    // 构建查询条件
    NativeSearchQuery nativeSearchQuery = new NativeSearchQueryBuilder().addAggregation(AggregationBuilders.filter("titles", QueryBuilders.termQuery("title", 1214666))).build();
    SearchHits<UserEntity> search = elasticsearchTemplate.search(nativeSearchQuery, UserEntity.class);
    return search;
}
Also used : NativeSearchQueryBuilder(org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder) UserEntity(com.javayh.elaticsearh.docment.UserEntity) NativeSearchQuery(org.springframework.data.elasticsearch.core.query.NativeSearchQuery)

Example 3 with UserEntity

use of com.javayh.elaticsearh.docment.UserEntity in project IT-Demo by yanghaiji.

the class EsRestTemplateImpl method create.

/**
 * <p>
 * 保存索引
 * </p>
 *
 * @param
 * @return void
 * @version 1.0.0
 * @author hai ji
 * @since 2022/2/9
 */
public void create() {
    UserEntity userEntity = UserEntity.builder().id(System.currentTimeMillis()).brand("javayh").images("es.png").price(2020.29).title("Java有货").build();
    elasticsearchTemplate.save(userEntity);
}
Also used : UserEntity(com.javayh.elaticsearh.docment.UserEntity)

Example 4 with UserEntity

use of com.javayh.elaticsearh.docment.UserEntity in project IT-Demo by yanghaiji.

the class EsRepoWeb method get.

/**
 * <p>
 * 根据id 查询
 * </p>
 *
 * @param
 * @return void
 * @version 1.0.0
 * @author hai ji
 * @since 2022/2/10
 */
@GetMapping
public void get() {
    UserEntity entity = esRepo.findById(1212L).orElse(null);
    System.out.println(entity);
}
Also used : UserEntity(com.javayh.elaticsearh.docment.UserEntity) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 5 with UserEntity

use of com.javayh.elaticsearh.docment.UserEntity in project IT-Demo by yanghaiji.

the class EsRestTemplateImpl method index.

public String index() {
    UserEntity userEntity = UserEntity.builder().id(System.currentTimeMillis()).brand("javayh").images("es.png").price(2020.29).title("Java有货").build();
    IndexQuery indexQuery = new IndexQueryBuilder().withObject(userEntity).build();
    String sys_user = elasticsearchTemplate.index(indexQuery, IndexCoordinates.of("sys_user"));
    return sys_user;
}
Also used : IndexQueryBuilder(org.springframework.data.elasticsearch.core.query.IndexQueryBuilder) IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery) UserEntity(com.javayh.elaticsearh.docment.UserEntity)

Aggregations

UserEntity (com.javayh.elaticsearh.docment.UserEntity)5 NativeSearchQuery (org.springframework.data.elasticsearch.core.query.NativeSearchQuery)2 NativeSearchQueryBuilder (org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder)2 IndexQuery (org.springframework.data.elasticsearch.core.query.IndexQuery)1 IndexQueryBuilder (org.springframework.data.elasticsearch.core.query.IndexQueryBuilder)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1