国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

easy-es 使用

這篇具有很好參考價(jià)值的文章主要介紹了easy-es 使用。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

1、pom中引入依賴

 <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>7.14.0</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-client</artifactId>
            <version>7.14.0</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>7.14.0</version>
        </dependency>

        <dependency>
            <groupId>cn.easy-es</groupId>
            <artifactId>easy-es-boot-starter</artifactId>
            <version>2.0.0-beta1</version>
        </dependency>

2、yml文件增加配置

easy-es:
  address: 192.168.3.133:9210
  enable: true
  db-config:
    map-underscore-to-camel-case: true
    id-type: customize
    refresh-policy: immediate
    enable-track-total-hits: true

3、實(shí)體索引

package com.cn.es.entity;

import cn.easyes.annotation.HighLight;
import cn.easyes.annotation.IndexField;
import cn.easyes.annotation.IndexId;
import cn.easyes.annotation.IndexName;
import cn.easyes.annotation.rely.Analyzer;
import cn.easyes.annotation.rely.FieldType;
import cn.easyes.annotation.rely.IdType;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

/**
 * description: ProductEntity <br>
 * date: 23.2.27 15:12 <br>
 * author: cn_yaojin <br>
 * version: 1.0 <br>
 */
@Setter
@Getter
@IndexName(value = "product_entity", shardsNum = 1, replicasNum = 1, aliasName = "Product")
//@Document(indexName = "product-index1", createIndex = true, type = "_doc")
public class ProductEntity {
    //id是業(yè)務(wù)中添加的,不是es自動(dòng)生成的
    @IndexId(type = IdType.CUSTOMIZE)
    private Long id;

    @HighLight(mappingField = "resume", fragmentSize = 10)//將查詢到的高亮內(nèi)容放到resume字段中
    @IndexField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_MAX_WORD, searchAnalyzer = Analyzer.IK_SMART)
    private String name;

    //拼音分詞
    @IndexField(fieldType = FieldType.TEXT, analyzer = Analyzer.PINYIN, searchAnalyzer = Analyzer.PINYIN)
    private String name1;

    //存放高亮
    @IndexField(exist = false)
    private String resume;


    @IndexField(fieldType = FieldType.KEYWORD)
    @ApiModelProperty(value = "銷量")
    private Integer saleNum;

    @IndexField(fieldType = FieldType.KEYWORD)
    @ApiModelProperty(value = "價(jià)格")
    private Double price;

    /**
     * 品牌ID
     */
    @IndexField(fieldType = FieldType.LONG)
    private Long brandId;

    /**
     * 分類ID
     */
    @IndexField(fieldType = FieldType.LONG)
    private Long categoryId;

    /**
     * 店鋪id
     */
    @IndexField(fieldType = FieldType.LONG)
    private Long shopId;

    @IndexField(fieldType = FieldType.KEYWORD)
    private Long addTime;



}

4、mapper

import cn.easyes.core.core.BaseEsMapper;
import com.cn.es.entity.ProductEntity;

public interface IProduc2Mapper extends BaseEsMapper<ProductEntity> {
}

5、service

package com.cn.es.service;

import cn.easyes.core.biz.EsPageInfo;
import cn.easyes.core.biz.SAPageInfo;
import cn.easyes.core.conditions.select.LambdaEsQueryWrapper;
import com.cn.es.entity.ProductEntity;
import com.cn.es.mapper.IProduc2Mapper;
import com.cn.es.vo.ProductSearch;
import com.cn.exception.MyException;
import com.cn.page.PageVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * description: Product2Service <br>
 * date: 23.3.20 14:29 <br>
 * author: cn_yaojin <br>
 * version: 1.0 <br>
 */
@Service
@Slf4j
public class Product2Service {

    @Autowired
    private IProduc2Mapper produc2Mapper;

    private String indexName = "product_entity";


    public void create() {
        boolean exist = this.produc2Mapper.existsIndex(indexName);
        if (!exist) {
            this.produc2Mapper.createIndex(indexName);
        } else {
            throw new MyException("索引已存在");
        }
    }

    public void drop() {
        boolean result = this.produc2Mapper.deleteIndex(indexName);
        System.out.println(result);
    }

    public void save(ProductEntity info) {
        info.setName1(info.getName()); //將商品名稱放到name1拼音字段中

        info.setAddTime(System.currentTimeMillis());
        var data = this.produc2Mapper.selectById(info.getId());
        if (data != null) {
            update(info);
        } else {
            this.produc2Mapper.insert(info);
        }

    }

    public void update(ProductEntity info) {
        this.produc2Mapper.updateById(info);
    }

    public EsPageInfo<ProductEntity> page(PageVo<ProductSearch> pageVo) {
        ProductSearch search = pageVo.getParam();
        LambdaEsQueryWrapper<ProductEntity> queryWrapper = new LambdaEsQueryWrapper<>();
        if (StringUtils.isNotEmpty(search.getName())) {
//            queryWrapper.like("name", search.getName());
//            queryWrapper.matchPhrase(ProductEntity::getName, search.getName());
            queryWrapper.matchPhrase(ProductEntity::getName1, search.getName())
                    .or().matchPhrase(ProductEntity::getName, search.getName());

//            queryWrapper.multiMatchQuery("name", search.getName());
        }
        if (search.getPrice1() > -1) {
            queryWrapper.ge("price", search.getPrice1());
        }
        if (search.getPrice2() > -1) {
            queryWrapper.le("price", search.getPrice2());
        }

        if (search.getSortPrice()) {
            queryWrapper.orderByDesc("price");
        }
        if (search.getSortSaleNum()) {
            queryWrapper.orderByDesc("saleNum");
        }

        EsPageInfo<ProductEntity> page = this.produc2Mapper.pageQuery(queryWrapper, pageVo.getPageNum(), pageVo.getPageSize());
        return page;
    }

    public Object searchAfter(ProductSearch search) {
        LambdaEsQueryWrapper<ProductEntity> queryWrapper = new LambdaEsQueryWrapper<>();
        if (StringUtils.isNotEmpty(search.getName())) {

            queryWrapper.matchPhrase(ProductEntity::getName1, search.getName())
                    .or().matchPhrase(ProductEntity::getName, search.getName());
        }

        if (search.getPrice1() > -1) {
            queryWrapper.ge("price", search.getPrice1());
        }
        if (search.getPrice2() > -1) {
            queryWrapper.le("price", search.getPrice2());
        }

        queryWrapper.orderByDesc("id"); //以id為排序方式

        SAPageInfo<ProductEntity> saPageInfo = produc2Mapper.searchAfterPage(queryWrapper, search.getNextSearchAfter(), search.getSize());

        return saPageInfo;
    }


    public void del(String id) {
        this.produc2Mapper.deleteById(id);
    }

    public static void main(String[] args) {
        System.out.println(System.currentTimeMillis());
    }

}

6、controller

package com.cn.es.controller;

import cn.easyes.core.biz.EsPageInfo;
import cn.easyes.core.biz.SAPageInfo;
import com.cn.es.entity.ProductEntity;
import com.cn.es.service.Product2Service;
import com.cn.es.vo.ProductSearch;
import com.cn.msg.ResultMsg;
import com.cn.page.PageVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping(value = "admin/product")
@Api(tags = "產(chǎn)品")
@Slf4j
public class ProductController {


    @Autowired
    private Product2Service product2Service;

    @ApiOperation(value = "新建索引")
    @GetMapping(value = "crate")
    public ResultMsg create() {
        this.product2Service.create();
        return ResultMsg.builder();
    }

    @ApiOperation(value = "刪除索引")
    @GetMapping(value = "drop")
    public ResultMsg drop() {
        this.product2Service.drop();
        return ResultMsg.builder();
    }

    @ApiOperation(value = "保存")
    @PostMapping(value = "save")
    public ResultMsg save(
            @RequestBody ProductEntity info
    ) {
        this.product2Service.save(info);
        return ResultMsg.builder();
    }


    @ApiOperation(value = "easy-es 淺分頁")
    @PostMapping(value = "page")
    public ResultMsg<EsPageInfo<ProductEntity>> page1(
            @RequestBody PageVo<ProductSearch> search
    ) {
        return ResultMsg.builder().setData(this.product2Service.page(search));
    }

    @ApiOperation(value = "easy-es searchAfter查詢分頁")
    @PostMapping(value = "page2")
    public ResultMsg<SAPageInfo<ProductEntity>> page2(
            @RequestBody ProductSearch search
    ) {
        return ResultMsg.builder().setData(this.product2Service.searchAfter(search));
    }

    @ApiOperation(value = "刪除")
    @GetMapping(value = "del")
    public ResultMsg del(
            @RequestParam String id
    ) {
        this.product2Service.del(id);
        return ResultMsg.builder();
    }

}

7、新增或修改數(shù)據(jù)

{
  "brandId": 0,
  "categoryId": 1,
  "id": 8,
  "multiField": "",
  "name": "烤肉、啤酒",
  "price": 130,
  "saleNum": 124,
  "shopId": 1
}

easy-es 使用,elasticsearch,jenkins,大數(shù)據(jù)

8、淺分頁

{
  "pageNum": 1,
  "pageSize": 20,
  "param": {
    "name": "",//支持拼音搜索:niurou
    "price1": -1,
    "price2": -1,
    "sortPrice": true,
    "sortSaleNum": true
  }
}

easy-es 使用,elasticsearch,jenkins,大數(shù)據(jù)

?9、searchAfter 分頁,必須有一個(gè)唯一的排序?qū)傩裕纾篿d

{
  "name": "牛肉面",
  "size": 2 //查詢2條
}

easy-es 使用,elasticsearch,jenkins,大數(shù)據(jù)

下一頁:

{
  "name": "",
  "size": 2,
  "nextSearchAfter": [
    "7"
  ]
}

easy-es 使用,elasticsearch,jenkins,大數(shù)據(jù)

當(dāng)使用??searchAfter分頁時(shí),想使用銷量、價(jià)格 等排序來展示數(shù)據(jù),需要結(jié)合一個(gè)唯一且連續(xù)的屬性來組合排序,否則容易導(dǎo)致數(shù)據(jù)丟失。比如當(dāng)牛肉面二細(xì)銷量為10、牛肉三細(xì)銷量也為10的時(shí)候,如果僅使用銷量作為排序字段,那么以上兩條數(shù)據(jù)只能查到一條。但是如果在銷量排序的基礎(chǔ)上,再新增一個(gè)唯一且連續(xù)的屬性來排序(該唯一且連續(xù)的屬性必須放在所有排序字段的最后面),那么可以避免數(shù)據(jù)丟失的問題。示例代碼如下:

 if (search.getSortSaleNum()) {
       queryWrapper.orderByDesc("saleNum"); //銷量排序
       queryWrapper.orderByDesc("_doc"); //doc是es自動(dòng)生成的,唯一且連續(xù),也可以使用id代替_doc
       //以上兩者組合使用,在銷量排序的基礎(chǔ)上,防止相同銷量數(shù)據(jù)的丟失,而且_doc排序必須放在最后面
 }

11、高亮查詢,高亮屬性已經(jīng)在實(shí)體:ProductEntity 中的name屬性上設(shè)置了,所以此處使用name字段正常查詢即可。

{
  "pageNum": 1,
  "pageSize": 20,
  "param": {
    "name": "牛肉面"
  }
}
{
  "msg": "成功",
  "data": {
    "total": 6,
    "list": [
      {
        "id": 5,
        "name": "牛肉面寬",
        "name1": "牛肉面寬",
        "resume": "<em>牛肉面</em>寬",
        "saleNum": 20,
        "price": 7,
        "brandId": 0,
        "categoryId": 1,
        "shopId": 1,
        "addTime": null
      },
      {
        "id": 1,
        "name": "牛肉面細(xì)",
        "name1": "牛肉面細(xì)",
        "resume": "<em>牛肉面</em>細(xì)",
        "saleNum": 7,
        "price": 7,
        "brandId": 0,
        "categoryId": 1,
        "shopId": 1,
        "addTime": null
      },
      {
        "id": 2,
        "name": "牛肉面毛細(xì)",
        "name1": "牛肉面毛細(xì)",
        "resume": "<em>牛肉面</em>毛細(xì)",
        "saleNum": 8,
        "price": 6,
        "brandId": 0,
        "categoryId": 1,
        "shopId": 1,
        "addTime": null
      },
      {
        "id": 3,
        "name": "牛肉面三細(xì)",
        "name1": "牛肉面三細(xì)",
        "resume": "<em>牛肉面</em>三細(xì)",
        "saleNum": 10,
        "price": 6.5,
        "brandId": 0,
        "categoryId": 1,
        "shopId": 1,
        "addTime": null
      },
      {
        "id": 4,
        "name": "牛肉面二細(xì)",
        "name1": "牛肉面二細(xì)",
        "resume": "<em>牛肉面</em>二細(xì)",
        "saleNum": 31,
        "price": 7.5,
        "brandId": 0,
        "categoryId": 1,
        "shopId": 1,
        "addTime": null
      },
      {
        "id": 6,
        "name": "牛肉面大寬",
        "name1": "牛肉面大寬",
        "resume": "<em>牛肉面</em>大寬",
        "saleNum": 10,
        "price": 7,
        "brandId": 0,
        "categoryId": 1,
        "shopId": 1,
        "addTime": null
      }
    ],
    "pageNum": 1,
    "pageSize": 20,
    "size": 6,
    "startRow": 0,
    "endRow": 5,
    "pages": 1,
    "prePage": 0,
    "nextPage": 0,
    "hasPreviousPage": false,
    "hasNextPage": false,
    "navigatePages": 8,
    "navigatePageNums": [
      1
    ],
    "navigateFirstPage": 1,
    "navigateLastPage": 1,
    "firstPage": true,
    "lastPage": true
  },
  "success": true,
  "code": 200
}

easy-es 使用,elasticsearch,jenkins,大數(shù)據(jù)文章來源地址http://www.zghlxwxcb.cn/news/detail-667190.html

到了這里,關(guān)于easy-es 使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • ES增強(qiáng)框架easy-es

    ES增強(qiáng)框架easy-es

    因?yàn)樽罱龅墓δ苁顷P(guān)于輿情的,所以數(shù)據(jù)量比較大的,本來打算用MySQL做時(shí)間分表來做,但是經(jīng)過一段時(shí)間的測(cè)試,發(fā)現(xiàn)數(shù)據(jù)量太大,用時(shí)間分表不能滿足性能的要求,所以決定將數(shù)據(jù)存儲(chǔ)改為ES,但是短時(shí)間內(nèi)改底層框架又不是一個(gè)小工程,時(shí)間上不允許,所以找到了一個(gè)很合適的框架

    2024年04月25日
    瀏覽(25)
  • SpringBoot集成Easy-Es

    SpringBoot集成Easy-Es

    Easy-Es(簡(jiǎn)稱EE)是一款基于ElasticSearch(簡(jiǎn)稱Es)官方提供的RestHighLevelClient打造的ORM開發(fā)框架,在 RestHighLevelClient 的基礎(chǔ)上,只做增強(qiáng)不做改變,為簡(jiǎn)化開發(fā)、提高效率而生 1、添加依賴 2、配置信息 3、啟動(dòng)類中添加 @EsMapperScan 注解,掃描 Mapper 文件夾 4、實(shí)體類和mapper 5、測(cè)試 h

    2024年02月02日
    瀏覽(25)
  • Springboot整合Easy-Es

    Springboot整合Easy-Es

    Springboot 2.7.5 JDK 17 Elasticsearch 7.14.0 Easy-Es 1.1.1 《點(diǎn)我進(jìn)入Easy-Es官網(wǎng)》 PS:目前Easy-Es暫不支持SpringBoot3.X 《安裝Elasticsearch教程》 pom.xml application.yml Document實(shí)體類 DocumentMapper (官方建議:Easy-Es的Mapper和MyBatis-Plus分開存放) 和MyBatis-Plus差不多都是繼承mapper,但是Easy-Es不需要繼承Se

    2024年02月10日
    瀏覽(17)
  • 運(yùn)用easy-es保存數(shù)據(jù)時(shí),報(bào)錯(cuò):cn.easyes.common.exception.EasyEsException: no such method:

    運(yùn)用easy-es保存數(shù)據(jù)時(shí),報(bào)錯(cuò):cn.easyes.common.exception.EasyEsException: no such method:

    cn.easyes.common.exception.EasyEsException: no such method: ?? ?at cn.easyes.common.utils.ExceptionUtils.eee(ExceptionUtils.java:39) ?? ?at cn.easyes.core.cache.BaseCache.lambda$setterMethod$6(BaseCache.java:127) ?? ?at cn.easyes.core.cache.BaseCache$$Lambda$2307/809171830.get(Unknown Source) ?? ?at java.util.Optional.orElseThrow(Optional.java:29

    2024年02月03日
    瀏覽(24)
  • ES商品搜索實(shí)戰(zhàn) Easy-Es搭配原生SearchSourceBuilder

    組裝查詢條件LambdaEsQueryWrapper,包含查詢條件,排序,分頁,高亮,去重 這里是搜索的條件組裝,封裝BoolQueryBuilder 這里就是方法的入口,productMapper.selectList(wrapper)和Mybatis-Plus的寫法基本上一摸一樣,如果不懂可以去看一下EE官方使用方法 Easy-Es

    2024年02月17日
    瀏覽(16)
  • SpringBoot整合Easy-ES操作演示文檔

    SpringBoot整合Easy-ES操作演示文檔

    1.1 官網(wǎng) Easy-ES官網(wǎng): https://www.easy-es.cn/ 官方示例: https://gitee.com/dromara/easy-es/tree/master/easy-es-sample 參考鏈接: https://blog.51cto.com/yueshushu/6193710 1.2 主要特性 **零侵入:**針對(duì)ES官方提供的RestHighLevelClient只做增強(qiáng)不做改變,引入EE不會(huì)對(duì)現(xiàn)有工程產(chǎn)生影響,使用體驗(yàn)如絲般順滑。 *

    2024年02月07日
    瀏覽(17)
  • 若依整合Easy-Es實(shí)現(xiàn)文章列表分頁查詢

    Easy-Es(簡(jiǎn)稱EE)是一款基于ElasticSearch(簡(jiǎn)稱Es)官方提供的RestHighLevelClient打造的ORM開發(fā)框架,在 RestHighLevelClient 的基礎(chǔ)上,只做增強(qiáng)不做改變,為簡(jiǎn)化開發(fā)、提高效率而生,您如果有用過Mybatis-Plus(簡(jiǎn)稱MP),那么您基本可以零學(xué)習(xí)成本直接上手EE,EE是MP的Es平替版,在有些方面甚至比M

    2024年01月16日
    瀏覽(20)
  • 關(guān)于這款開源的ES的ORM框架-Easy-Es適合初學(xué)者入手不?

    關(guān)于這款開源的ES的ORM框架-Easy-Es適合初學(xué)者入手不?

    最近筆者為了撿回以前自學(xué)的ES知識(shí),準(zhǔn)備重新對(duì)ES的一些基礎(chǔ)使用做個(gè)大致學(xué)習(xí)總結(jié)。然后在摸魚逛開源社區(qū)時(shí)無意中發(fā)現(xiàn)了一款不錯(cuò)的ElasticSearch插件-Easy-ES,可稱之為“ES界的MyBatis-Plus”。聯(lián)想到之前每次用RestHighLevelClient寫一些DSL操作時(shí)都很麻煩(復(fù)雜點(diǎn)的搜索代碼量確實(shí)

    2024年02月07日
    瀏覽(20)
  • 【別再做XX外賣啦!和我從零到1編寫Mini版Easy-ES】完成一個(gè)Mapper模型

    【別再做XX外賣啦!和我從零到1編寫Mini版Easy-ES】完成一個(gè)Mapper模型

    作者:沈自在 代碼倉(cāng)庫:https://gitee.com/tian-haoran/mini-easy-es 本節(jié)教程分支:https://gitee.com/tian-haoran/mini-easy-es/tree/course_02_create_mapper/ ??注意:本項(xiàng)目會(huì)持續(xù)更新,直到功能完善 1.1.1 什么是 FactoryBean接口? 很多同學(xué)都知道 BeanFactory 接口,這個(gè)是大名鼎鼎的Spring中的核心接口,

    2024年02月04日
    瀏覽(44)
  • E往無前 | 海量數(shù)據(jù)ES 擴(kuò)展難?騰訊云大數(shù)據(jù)ES 擴(kuò)展百萬級(jí)分片也“So Easy~”

    E往無前 | 海量數(shù)據(jù)ES 擴(kuò)展難?騰訊云大數(shù)據(jù)ES 擴(kuò)展百萬級(jí)分片也“So Easy~”

    《E往無前》系列將著重展現(xiàn)騰訊云ES在持續(xù)深入優(yōu)化客戶所關(guān)心的「?。】?!穩(wěn)!」訴求,能夠在低成本的同時(shí)兼顧高可用、高性能、高穩(wěn)定等特性,可以滿足微盟、小紅書、微信支付等內(nèi)外部大客戶的核心場(chǎng)景需求。 E往無前?|?海量數(shù)據(jù)ES擴(kuò)展難?騰訊云ES 擴(kuò)展百萬級(jí)分片

    2024年02月06日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包