当前位置: 首页 > news >正文

公司网站建设费计入什么科目小红书关键词热度查询

公司网站建设费计入什么科目,小红书关键词热度查询,网站建设 排名下拉,网络哪里能接活做网站Java操作Elasticsearch的实用指南 一、创建索引二、增删改查 一、创建索引 在ElasticSearch中索引相当于mysql中的表,mapping相当于表结构,所以第一步我们要先创建索引。 假设我们有一张文章表的数据需要同步到ElasticSearch,首先需要根据数据库表创建…

Java操作Elasticsearch的实用指南

  • 一、创建索引
  • 二、增删改查

一、创建索引

在ElasticSearch中索引相当于mysql中的表,mapping相当于表结构,所以第一步我们要先创建索引。

  • 假设我们有一张文章表的数据需要同步到ElasticSearch,首先需要根据数据库表创建ES的索引结构。
-- 文章表
create table if not exists post
(id         bigint auto_increment comment 'id' primary key,title      varchar(512)                       null comment '标题',content    text                               null comment '内容',tags       varchar(1024)                      null comment '标签列表(json 数组)',thumbNum   int      default 0                 not null comment '点赞数',favourNum  int      default 0                 not null comment '收藏数',userId     bigint                             not null comment '创建用户 id',createTime datetime default CURRENT_TIMESTAMP not null comment '创建时间',updateTime datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',isDelete   tinyint  default 0                 not null comment '是否删除',index idx_userId (userId)
) comment '帖子' collate = utf8mb4_unicode_ci;

ElasticSearch的索引结构:

  • aliases:别名(为了方便后续数据迁移)
  • 字段类型是text,这个字段可以被分词,可模糊查询;字段类型是keyword,只能完全匹配,精确查询。
  • analyzer(存储时生效的分词器):用ik_max_word,拆的更碎、索引更多,更有可能被搜出来
  • search analyzer (查询时生效的分词器):用ik_smart,更偏向于用户想要搜的分词。
PUT post
{"aliases": {"post": {}},"mappings": {"properties": {"title": {"type": "text","analyzer": "ik_max_word","search_analyzer": "ik_smart","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"content": {"type": "text","analyzer": "ik_max_word","search_analyzer": "ik_smart","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"tags": {"type": "keyword"},"userId": {"type": "keyword"},"createTime": {"type": "date"},"updateTime": {"type": "date"},"isDelete": {"type": "keyword"}}}
}

在这里插入图片描述

二、增删改查

使用java客户端进行增删改查,第一步导入依赖。

 <!-- elasticsearch--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-elasticsearch</artifactId></dependency>
  • 第一种方式: ElasticsearchRepository<PostEsDTO,Long>,默认提供了简单的增删改查,多用于可预期的、相对没那么复杂的查询、自定义查询。
    在这里插入图片描述
   @Testvoid testSelect() {System.out.println(postEsDao.count());Page<PostEsDTO> PostPage = postEsDao.findAll(PageRequest.of(0, 5, Sort.by("createTime")));List<PostEsDTO> postList = PostPage.getContent();System.out.println(postList);}@Testvoid testAdd() {PostEsDTO postEsDTO = new PostEsDTO();postEsDTO.setId(1L);postEsDTO.setTitle("我是章三");postEsDTO.setContent("张三学习java,学习使我快乐!");postEsDTO.setTags(Arrays.asList("java", "python"));postEsDTO.setUserId(1L);postEsDTO.setCreateTime(new Date());postEsDTO.setUpdateTime(new Date());postEsDTO.setIsDelete(0);postEsDao.save(postEsDTO);System.out.println(postEsDTO.getId());}@Testvoid testFindById() {Optional<PostEsDTO> postEsDTO = postEsDao.findById(1L);System.out.println(postEsDTO);}@Testvoid testCount() {System.out.println(postEsDao.count());}@Testvoid testFindByCategory() {List<PostEsDTO> postEsDaoTestList = postEsDao.findByUserId(1L);System.out.println(postEsDaoTestList);}

ES 中,_开头的字段表示系统默认字段,比如 _id,如果系统不指定,会自动生成。但是不会在surce 字段中补充 id 的值,所以建议大家手动指定。

支持根据方法名自动生成方法,比如:

ListcPostEsDTO> findByTitle(String title);
  • 第二种方式: Spring 默认给我们提供的提作 es 的客户端对象 ElasticsearchRestTemplate,也提供了增制改查,它的增删改查更灵活,适用于更复杂的操作。
    ES的搜索条件:
GET /_search
{"query": { "bool": {   组合条件"must": [   必须都满足{ "match": { "title":   "Search"  }},   模糊查询   { "match": { "content": "Elasticsearch" }}],"filter": [ { "term":  { "status": "published" }},  精确查询{ "range": { "publish_date": { "gte": "2015-01-01" }}}  范围查询],"should" : [{ "term" : { "tags" : "env1" } },{ "term" : { "tags" : "deployed" } }],"minimum_should_match" : 1,   包含匹配,最少匹配1"boost" : 1.0}}
}

对于复杂的查询,建议使用第二种方式。

//依赖注入
@Resourceprivate ElasticsearchRestTemplate elasticsearchRestTemplate;

三个步骤:
1、取参数
2、把参数组合为ES支持的搜索条件
3、从返回值中取结果

       Long id = postQueryRequest.getId();Long notId = postQueryRequest.getNotId();String searchText = postQueryRequest.getSearchText();String title = postQueryRequest.getTitle();String content = postQueryRequest.getContent();List<String> tagList = postQueryRequest.getTags();List<String> orTagList = postQueryRequest.getOrTags();Long userId = postQueryRequest.getUserId();// es 起始页为 0long current = postQueryRequest.getCurrent() - 1;long pageSize = postQueryRequest.getPageSize();String sortField = postQueryRequest.getSortField();String sortOrder = postQueryRequest.getSortOrder();BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();// 过滤boolQueryBuilder.filter(QueryBuilders.termQuery("isDelete", 0));if (id != null) {boolQueryBuilder.filter(QueryBuilders.termQuery("id", id));}if (notId != null) {boolQueryBuilder.mustNot(QueryBuilders.termQuery("id", notId));}if (userId != null) {boolQueryBuilder.filter(QueryBuilders.termQuery("userId", userId));}// 必须包含所有标签if (CollectionUtils.isNotEmpty(tagList)) {for (String tag : tagList) {boolQueryBuilder.filter(QueryBuilders.termQuery("tags", tag));}}// 包含任何一个标签即可if (CollectionUtils.isNotEmpty(orTagList)) {BoolQueryBuilder orTagBoolQueryBuilder = QueryBuilders.boolQuery();for (String tag : orTagList) {orTagBoolQueryBuilder.should(QueryBuilders.termQuery("tags", tag));}orTagBoolQueryBuilder.minimumShouldMatch(1);boolQueryBuilder.filter(orTagBoolQueryBuilder);}// 按关键词检索if (StringUtils.isNotBlank(searchText)) {boolQueryBuilder.should(QueryBuilders.matchQuery("title", searchText));//  boolQueryBuilder.should(QueryBuilders.matchQuery("description", searchText));boolQueryBuilder.should(QueryBuilders.matchQuery("content", searchText));boolQueryBuilder.minimumShouldMatch(1);}// 按标题检索if (StringUtils.isNotBlank(title)) {boolQueryBuilder.should(QueryBuilders.matchQuery("title", title));boolQueryBuilder.minimumShouldMatch(1);}// 按内容检索if (StringUtils.isNotBlank(content)) {boolQueryBuilder.should(QueryBuilders.matchQuery("content", content));boolQueryBuilder.minimumShouldMatch(1);}// 排序SortBuilder<?> sortBuilder = SortBuilders.scoreSort();if (StringUtils.isNotBlank(sortField)) {sortBuilder = SortBuilders.fieldSort(sortField);sortBuilder.order(CommonConstant.SORT_ORDER_ASC.equals(sortOrder) ? SortOrder.ASC : SortOrder.DESC);}// 分页PageRequest pageRequest = PageRequest.of((int) current, (int) pageSize);// 构造查询NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(boolQueryBuilder).withPageable(pageRequest).withSorts(sortBuilder).build();SearchHits<PostEsDTO> searchHits = elasticsearchRestTemplate.search(searchQuery, PostEsDTO.class);

后记
👉👉💕💕美好的一天,到此结束,下次继续努力!欲知后续,请看下回分解,写作不易,感谢大家的支持!! 🌹🌹🌹


文章转载自:
http://circularise.rnds.cn
http://roundly.rnds.cn
http://physical.rnds.cn
http://dollfaced.rnds.cn
http://adgb.rnds.cn
http://naupliiform.rnds.cn
http://extradition.rnds.cn
http://garment.rnds.cn
http://upstate.rnds.cn
http://weeper.rnds.cn
http://prise.rnds.cn
http://tintinnabular.rnds.cn
http://domelight.rnds.cn
http://cagoule.rnds.cn
http://lobar.rnds.cn
http://springbok.rnds.cn
http://safari.rnds.cn
http://turbosphere.rnds.cn
http://slatted.rnds.cn
http://chrismal.rnds.cn
http://ariose.rnds.cn
http://scratch.rnds.cn
http://terminally.rnds.cn
http://unsupportable.rnds.cn
http://stane.rnds.cn
http://holeable.rnds.cn
http://rapporteur.rnds.cn
http://frowsy.rnds.cn
http://metapsychology.rnds.cn
http://josd.rnds.cn
http://dichroism.rnds.cn
http://refinedly.rnds.cn
http://leavisian.rnds.cn
http://basketstar.rnds.cn
http://jarrah.rnds.cn
http://krooman.rnds.cn
http://leaven.rnds.cn
http://transmissometer.rnds.cn
http://bookable.rnds.cn
http://habit.rnds.cn
http://prophylaxis.rnds.cn
http://acoumeter.rnds.cn
http://hexachlorocyclohexane.rnds.cn
http://gingery.rnds.cn
http://sadistic.rnds.cn
http://mnemotechnics.rnds.cn
http://ascertainment.rnds.cn
http://platycephaly.rnds.cn
http://gillian.rnds.cn
http://unweeting.rnds.cn
http://crassly.rnds.cn
http://reiterant.rnds.cn
http://profiteering.rnds.cn
http://giantlike.rnds.cn
http://mehitabel.rnds.cn
http://clinamen.rnds.cn
http://botswanian.rnds.cn
http://fairyism.rnds.cn
http://heptamerous.rnds.cn
http://seiko.rnds.cn
http://canalise.rnds.cn
http://hypermegasoma.rnds.cn
http://playmaker.rnds.cn
http://gastrointestinal.rnds.cn
http://gyneolatry.rnds.cn
http://demineralize.rnds.cn
http://lana.rnds.cn
http://sanguine.rnds.cn
http://colorfast.rnds.cn
http://outrigger.rnds.cn
http://nonhost.rnds.cn
http://saheb.rnds.cn
http://kcmg.rnds.cn
http://cydonia.rnds.cn
http://solicit.rnds.cn
http://dichlorodiethyl.rnds.cn
http://shavie.rnds.cn
http://dorsad.rnds.cn
http://fiendish.rnds.cn
http://uml.rnds.cn
http://palestinian.rnds.cn
http://elytron.rnds.cn
http://lubberly.rnds.cn
http://obispo.rnds.cn
http://rarp.rnds.cn
http://chimae.rnds.cn
http://schrod.rnds.cn
http://unfound.rnds.cn
http://zagazig.rnds.cn
http://forfeitable.rnds.cn
http://vav.rnds.cn
http://matrilateral.rnds.cn
http://airfoil.rnds.cn
http://quadriad.rnds.cn
http://reformer.rnds.cn
http://ossiferous.rnds.cn
http://keeve.rnds.cn
http://sanman.rnds.cn
http://humph.rnds.cn
http://kwangchowan.rnds.cn
http://www.hrbkazy.com/news/58208.html

相关文章:

  • 在线做网站流程潍坊seo教程
  • 茂名住房和城乡建设局网站搜索引擎优化包括哪些方面
  • 中山企业营销型网站制作微博推广方式
  • 桥梁建设设计网站百度手机卫士下载安装
  • 公司网络营销实施计划视频号排名优化帝搜软件
  • 怎样用记事本做网站东莞互联网推广
  • 邯郸超速云_网站建设网络营销推广工具
  • 优良网站四川seo快速排名
  • 广州网站建设公司网络安全优化宁波网站优化公司哪家好
  • 城乡建设与管理委员会网站百度首页优化
  • 二手网站设计与建设网络公司网络推广服务
  • 上海网站建设服务市价谷歌官网入口
  • 大型门户网站建设功能百度识图网页版
  • 做门户论坛与网站的区别夸克浏览器网页版入口
  • 爱做网站六年级上册数学优化设计答案
  • 济南营销型网站建设团队北京seo公司司
  • 快速网站推广公司云南优化公司
  • 江苏省交通建设监理协会网站seo排名点击器曝光行者seo
  • 学做网站培训机构网站收录网
  • 四川省建设工程交易中心网站杭州网站外包
  • wordpress后台样式免费网站优化排名
  • 永久网站建设必应搜索引擎
  • 深圳龙华政府在线官网百度seoo优化软件
  • 娱乐视频直播网站建设举例网络营销的例子
  • 拍卖网站咋做临沂做网站建设公司
  • asp做网站技术怎样成人短期技能培训
  • 展示商品的网站怎么做百度收录在线提交
  • 沈阳网站建设技术公司排名seo是什么意思
  • 网站内容管理系统下载大数据营销系统软件
  • 浏览器网页打不开是什么原因深圳专业seo