当前位置:网站首页>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());
}边栏推荐
- Class bytecode file
- Js实现继承的六种方式
- Wallys/3 × 3/2 × 2 MIMO 802.11ac Mini PCIe Wi-Fi Module, Dual Band, 2,4GHz / 5GHz/QCN9074
- 单细胞代码解析-妇科癌症单细胞转录组及染色质可及性分析1
- Blackmagic Fusion Studio 18
- Quickly complete the unit test junit4 setting of intelij idea
- In the morning, Tencent took out 38K, which let me see the ceiling of the foundation
- 头文件是必须的吗?跟一跟编译过程~~~
- 使用matplotlib模拟线性回归
- The use and Simulation of character and string library functions in C language
猜你喜欢

Iqiyi Tiktok reconciled, Weibo lying gun?

Development Series III of GaN (lapgan, srgan)
![[leetcode] 30. Concatenate substrings of all words](/img/21/3965532a31553cfe6edf64ca5de3f4.png)
[leetcode] 30. Concatenate substrings of all words

C language to achieve a static version of the address book

The ability to detect movement in vivo and build a safe and reliable payment level "face brushing" experience

Socat port forwarding

Df2net 3D model deployment

700. Search DFS method in binary search tree

C # print reports using fastreport.net

ansible自动化运维详解(五)ansible中变量的设定使用、JINJA2模板的使用以及ansible的加密控制
随机推荐
Openlayers: point aggregation effect
Getaverse,走向Web3的远方桥梁
After separation, the impression notes are still difficult to live, but there are many coquettish operations
ansible自动化运维详解(五)ansible中变量的设定使用、JINJA2模板的使用以及ansible的加密控制
Six ways for JS to implement inheritance
Interview assault 66: what is the difference between request forwarding and request redirection?
new也可以创建对象,为什么需要工厂模式?
再见收费的Navicat!这款开源的数据库管理工具界面更炫酷!
C language custom types - Enumeration
C language custom type explanation - structure
Memory allocation and recycling strategy
Detailed explanation of ansible automatic operation and maintenance (V) the setting and use of variables in ansible, the use of jinja2 template and the encryption control of ansible
Eth POS 2.0 stacking test network pledge process
Preliminary understanding of redis
JS image conversion Base64 Base64 conversion to file object
es(1)
NPM install reported -4058 error
还在从零开始搭建项目?这款升级版快速开发脚手架值得一试!
ROC and AUC details of the recommended system
阿里巴巴/166获得店铺的所有商品 API使用说明