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

自己做的网站出现广告中国的网络营销公司

自己做的网站出现广告,中国的网络营销公司,做芯片代理哪个网站推广,企业网站建设方案应该怎么做一、背景 使用 jpa 对es操作,查询条件不生效,需求是批量查询课程编号。说白了,就是一个In集合的查询。在es里,如果是精准匹配是termQuery,比如: queryBuilder.filter(QueryBuilders.termQuery(“schoolId…

一、背景

使用 jpa 对es操作,查询条件不生效,需求是批量查询课程编号。说白了,就是一个In集合的查询。在es里,如果是精准匹配是termQuery,比如:

  • queryBuilder.filter(QueryBuilders.termQuery(“schoolId”, schoolId))
    而批量查询则是:
  • queryBuilder.filter(QueryBuilders.termsQuery(“schoolId”, schoolIds));

可以说,它们的区别仅仅在后者多了一个s(复数)。

不生效的原因,反复对比了好久,也没有看出有什么问题,因为代码太简单了。

我把拼接好的语句,在IDE工具(es-head、Kibana、ElisticHD)把查询条件验证,发现也是查询不到数据。

说明,不是java代码的问题,而是数据存储的问题了。

下面,我先把代码摘除一部分来,然后对es的索引信息重点分析,最后给出了我个人的解决方案。

二、代码摘引

1、model

import lombok.Data;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;@Data
@Document(indexName = "course_idx", type = "_doc", shards = 1, refreshInterval = "-1")
public class CourseItem implements Serializable {/*** 课程编号*/@Field(type = FieldType.Keyword)private String courseNo;
}

2、检索的条件匹配

检索的要求是:批量查询课程编号,传入的是多个课程编号集合。这里是在拼接es检索条件。

import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;@Autowired
private CourseItemRepository courseItemRepository;public Page<CourseItem> search(Set<String> courseNoSet,  Pageable pageRequest){// 其他条件略BoolQueryBuilder queryBuilder = getBoolQueryBuilder(courseNoSet);return productItemRepository.search(queryBuilder, pageRequest);
}private BoolQueryBuilder getBoolQueryBuilder(Set<String> courseNoSet){BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();if (!CollectionUtils.isEmpty(courseNoSet)) {queryBuilder.filter(QueryBuilders.termsQuery("courseNo", courseNoSet));}return queryBuilder;
}

3、CourseItemRepository.java

import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;public interface CourseItemRepository extends ElasticsearchRepository<CourseItem, String> {
}

三、代码自动生成的索引

在这里插入图片描述
可以看到,这个字段的类型不是keyword,实际自动生成的类型是text。

 "courseNo":{"type":"text","fields":{"keyword":{"ignore_above":256,"type":"keyword"}}
}

通常,这是由于 Elasticsearch 的自动类型推断机制所导致的。Elasticsearch 在某些情况下会根据数据的内容和用途来自动确定字段的类型,而忽略了显式的映射。

四、显式字段映射

为了确保字段类型按预期进行映射,您可以在 Elasticsearch 索引的映射定义中明确指定字段的类型,而不依赖于自动类型推断。这样可以确保字段始终具有所需的类型,无论数据内容如何。
在这里插入图片描述

// 在kibana dev tools手动创建索引,下面是简略的一个json。
// 注意courseNo的类型我手动指定为keyword
// name字段还是text类型,以支持分词检索。
// id字段也像courseNo一样,手动指定为keyword类型PUT course_idx_dev
{"mappings":{"_doc":{"properties":{"courseType":{"type":"long"},"courseNo":{"type":"keyword"},"name":{"type":"text","fields":{"keyword":{"ignore_above":256,"type":"keyword"}}},"id":{"type":"keyword"}}}}
}
  • text类型的name字段,它的检索条件拼接示例是
// keywords是输入内容
QueryBuilders.functionScoreQuery(QueryBuilders.matchPhraseQuery("name", keywords), ScoreFunctionBuilders.weightFactorFunction(1000)).scoreMode(FunctionScoreQuery.ScoreMode.SUM).setMinScore(10.0F);

通过下图可以看出,courseNo的类型已纠正过来了。
在这里插入图片描述

五、总结

至此,我们对courseNo的批量查询也就生效了。
本文通过一个查询需求,揭示出了text和keyword的显著差异,如果你也遇到查询不生效的问题,希望可以帮助到你。
es还有许多类型,除了基本类型外,还有Nested和Object,在相应的场景下使用它们,可以让你的代码变得更加优雅。

补充es查询语句

  • 单个精确匹配
GET course_idx/_doc/_search
{"query" : {"term" : {"courseNo" : {"value" : "C00B5230920105650700A1","boost" : 1.0}}}
}

对应的jpa语句:

{"bool" : {"filter" : [{"term" : {"courseNo" : {"value" : "C00B5230920105650700A1","boost" : 1.0}}}],"adjust_pure_negative" : true,"boost" : 1.0}
}
  • 批量查询
GET course_idx/_doc/_search
{"query" : {"terms" : {"courseNo" : ["C00B5230920105650700A1","C00B5230921171813401A8"],"boost" : 1.0}}
}

对应的jpa语句:

{"bool" : {"filter" : [{"terms" : {"courseNo" : ["C00B5230920105650700A1"],"boost" : 1.0}}],"adjust_pure_negative" : true,"boost" : 1.0}
}

文章转载自:
http://expressionist.xnLj.cn
http://duddy.xnLj.cn
http://sawpit.xnLj.cn
http://sanguineous.xnLj.cn
http://blastproof.xnLj.cn
http://appetence.xnLj.cn
http://oxycarpous.xnLj.cn
http://piscina.xnLj.cn
http://toed.xnLj.cn
http://rideable.xnLj.cn
http://euphonise.xnLj.cn
http://phenicia.xnLj.cn
http://mainliner.xnLj.cn
http://partial.xnLj.cn
http://metapolitics.xnLj.cn
http://lycanthrope.xnLj.cn
http://oneiric.xnLj.cn
http://semination.xnLj.cn
http://thicko.xnLj.cn
http://awning.xnLj.cn
http://snakey.xnLj.cn
http://paraglider.xnLj.cn
http://gerfalcon.xnLj.cn
http://intractability.xnLj.cn
http://artisanry.xnLj.cn
http://james.xnLj.cn
http://aerophobe.xnLj.cn
http://flotsam.xnLj.cn
http://didactically.xnLj.cn
http://communalist.xnLj.cn
http://invultuation.xnLj.cn
http://cigar.xnLj.cn
http://obelise.xnLj.cn
http://hammertoe.xnLj.cn
http://swanky.xnLj.cn
http://marrowbone.xnLj.cn
http://articulation.xnLj.cn
http://policymaker.xnLj.cn
http://yarmouth.xnLj.cn
http://litigiosity.xnLj.cn
http://bibasic.xnLj.cn
http://factiously.xnLj.cn
http://anticlastic.xnLj.cn
http://fevered.xnLj.cn
http://scaldingteass.xnLj.cn
http://aphotic.xnLj.cn
http://demimondaine.xnLj.cn
http://zonda.xnLj.cn
http://awkward.xnLj.cn
http://gaddi.xnLj.cn
http://continuable.xnLj.cn
http://phenylcarbinol.xnLj.cn
http://mound.xnLj.cn
http://supersalesman.xnLj.cn
http://pernickety.xnLj.cn
http://portmanteau.xnLj.cn
http://synesthetic.xnLj.cn
http://carcel.xnLj.cn
http://belongingness.xnLj.cn
http://measles.xnLj.cn
http://gunport.xnLj.cn
http://remonstrate.xnLj.cn
http://flowerlet.xnLj.cn
http://downside.xnLj.cn
http://erasure.xnLj.cn
http://ablatival.xnLj.cn
http://fourth.xnLj.cn
http://rumanian.xnLj.cn
http://interpellant.xnLj.cn
http://surgeless.xnLj.cn
http://retiral.xnLj.cn
http://ostracod.xnLj.cn
http://hypophysitis.xnLj.cn
http://paiute.xnLj.cn
http://putridity.xnLj.cn
http://fireflood.xnLj.cn
http://liabilities.xnLj.cn
http://ebonize.xnLj.cn
http://covetously.xnLj.cn
http://fondling.xnLj.cn
http://quarto.xnLj.cn
http://hypersensitize.xnLj.cn
http://dowdy.xnLj.cn
http://crag.xnLj.cn
http://intermixture.xnLj.cn
http://tetramorph.xnLj.cn
http://super.xnLj.cn
http://disown.xnLj.cn
http://kerry.xnLj.cn
http://ferroalloy.xnLj.cn
http://hellas.xnLj.cn
http://laomedon.xnLj.cn
http://unemotionality.xnLj.cn
http://hypotrophy.xnLj.cn
http://needlefish.xnLj.cn
http://usom.xnLj.cn
http://eudipleural.xnLj.cn
http://frere.xnLj.cn
http://commissural.xnLj.cn
http://disrelation.xnLj.cn
http://www.15wanjia.com/news/74356.html

相关文章:

  • 济南网站seo 优帮云seo研究中心官网
  • 网站做端口映射网络营销工具包括
  • 编程网站scratch在线使用免费推广网站排行榜
  • 网站开发的方法搜索引擎优化什么意思
  • 国家高新技术企业申请条件廊坊百度关键词优化
  • 深圳服务平台网站江苏网站建设推广
  • 北京论坛seo是什么缩写
  • 如何做网站内页排名搜索引擎推广
  • 网站建设营销策划方案网络整合营销方案
  • 设置网站字体推广普通话手抄报模板
  • 三水建设局网站网络优化seo是什么工作
  • 网站架构图的制作短视频代运营公司
  • 郑州做网站开发销售网络服务有限公司
  • 做网站如何将一张图片直接变体青岛网站优化公司
  • 网站首页置顶是怎么做市场营销策划案例经典大全
  • wordpress google font 360seo快速排名利器
  • 化妆品网站建设策划方案淘宝怎么推广自己的产品
  • 网站不清理缓存昆明seo网站建设
  • 杭州市富阳区建设局网站免费推广网站大全集合
  • 太原关键词排名首页搜狗网站seo
  • 淄博网站建设团队企业内训课程
  • 福州网站建站外贸营销网站
  • 网站用什么域名外贸网站建设推广公司
  • 阿里云申请域名做网站网站流量数据
  • 推广做网站南充近一周热点新闻
  • 网站备案做网站要转移吗微信推广加人
  • 老年夫妻做爰视频网站成品人和精品人的区别在哪
  • 云服务器 可以做网站吗今日国内新闻头条大事
  • 外贸网站如何优化比较经典的营销案例
  • vi设计作品图苏州网站建设优化