当前位置:网站首页>0621~ES&Lucene
0621~ES&Lucene
2022-07-24 17:43:00 【生活可真难啊】
全文检索的概念:先建立索引,然后对索引进行搜索的过程叫做全文检索;
全文检索的特点:1.关键词高亮;
2.只处理文本,不处理语义;
3.相关度,关键字最多的排在前面;
ES:页面端口:9200;
代码端口:9300;
Kibana端口号:5601;
全文索引架构(重点):
索引创建: 1.分词;
2.词态大小写转换;
3.排序;
4.合并;
5.形成倒排索引文档;
索引搜索:
1.根据关键字搜索倒排索引文档,找到id;
2.根据id到索引库的数据区定位到数据;
ES创建连接的方式 :
//创建连接
public static TransportClient getClient(){
// on startup
TransportClient client = null;
try {
client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
} catch (UnknownHostException e) {
e.printStackTrace();
}
return client;
}用es在Java里操作新增操作
//新增操作
@Test
public void save(){
//创建链接
TransportClient client = EsDemo.getClient();
IndexRequestBuilder indexRequestBuilder = client.prepareIndex("pethome", "user", "37");
Map<String, Object> map = new HashMap<>();
map.put("name","新增的名字");
map.put("age",26);
map.put("sex",0);
map.put("id",1);
indexRequestBuilder.setSource(map).get();
System.out.println(indexRequestBuilder.setSource(map));
client.close();
}条件查询:
// 查询用户名字中包含zs,1 2 // 性别等于0,1 2 // 年龄18-80岁 ,1 2 // 按照年龄倒排序, 1 2 // 取第二页,每页10条 1 2
@Test
public void Estest(){
TransportClient client = getClient();
SearchRequestBuilder prepareSearch = client.prepareSearch("pethome");
prepareSearch.setTypes("user");
// 取第二页,每页10条 1 2
prepareSearch.setFrom(1).setSize(5);
// 按照年龄倒排序, 1 2
prepareSearch.addSort("age",SortOrder.DESC);
BoolQueryBuilder query = QueryBuilders.boolQuery();
// 查询用户名字中包含zs,1
query.must(QueryBuilders.matchQuery("name","zs"));
// 年龄18-80岁 ,1
query.filter(QueryBuilders.rangeQuery("age").gte(18).lte(80));
// 性别等于0,1 2
query.filter(QueryBuilders.termQuery("sex","1"));
SearchResponse searchResponse = prepareSearch.setQuery(query).get();
SearchHits hits = searchResponse.getHits();
SearchHit[] searchHits = hits.getHits();
for (SearchHit searchHit : searchHits) {
System.out.println(searchHit.getSource());
}边栏推荐
- 邻接表的定义和存储以及有向图无向图的邻接存储
- Nearly 30 colleges and universities were named and praised by the Ministry of education!
- [waiting for insurance] what does waiting for insurance rectification mean? What are the rectification contents?
- ROC and AUC details of the recommended system
- Number theory division block explanation example: 2021 Shaanxi Race C
- C语言自定义类型讲解 — 结构体
- JS & TS learning summary
- 使用Prometheus+Grafana监控MySQL性能指标
- Huawei machine test - topic core test point
- 20 -- validate palindrome string
猜你喜欢

C语言自定义类型讲解 — 联合体

二维卷积——torch.nn.conv2d的使用

SV强制类型转换和常数

【网络安全】网站中间件存在的解析漏洞

近30所高校,获教育部点名表扬!

700. Search DFS method in binary search tree

Today, I met a 38K from Tencent, which let me see the ceiling of the foundation

C语言中的字符与字符串库函数的使用以及模拟实现

Dry goods | three sub domain name collection tools worth collecting

Review and analysis of noodle dishes
随机推荐
Baidu PaddlePaddle easydl x wesken: see how to install the "eye of AI" in bearing quality inspection
Tensorflow introductory tutorial (38) -- V2 net
213. 打家劫舍 II-动态规划
还在用命令行看日志?快用Kibana吧,可视化日志分析YYDS!
Mobile robot (IV) four axis aircraft
快速完成intelij idea的单元测试JUnit4设置
Tensorflow introductory tutorial (40) -- acunet
Introduction and use of Pinia
Awk from entry to earth (17) awk multiline writing
深入解析著名的阿里云Log4j 漏洞
The solution of single chip microcomputer not supporting printf floating point type
Fast power writing
The most powerful programmer on the earth is equipped with a "three piece set". Do you know what it is?
Getaverse, a distant bridge to Web3
微信朋友圈的高性能复杂度分析
How to remove the top picture of the bubble skin article details of solo blog
Js实现继承的六种方式
Six ways for JS to implement inheritance
分家后印象笔记过日子依然不好过,骚操作却不少
Gan Development Series II (pggan, Singan)