当前位置:网站首页>0621~ES&Lucene
0621~ES&Lucene
2022-07-24 17:47:00 【Life is so hard】
The concept of full text retrieval : Index first , Then the process of searching the index is called full-text search ;
The characteristics of full-text retrieval :1. Key words highlight ;
2. Process text only , Do not process semantics ;
3. Correlation degree , The most keywords are in the front ;
ES: Page port :9200;
Code port :9300;
Kibana Port number :5601;
Full text indexing architecture ( a key ):
Index creation : 1. participle ;
2. Word case conversion ;
3. Sort ;
4. Merge ;
5. Form inverted index document ;
Index search :
1. Search inverted index documents according to keywords , find id;
2. according to id Locate the data area of the index library to the data ;
ES How to create a connection :
// Create connection
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;
}use es stay Java Add operation in
// New operation
@Test
public void save(){
// Create links
TransportClient client = EsDemo.getClient();
IndexRequestBuilder indexRequestBuilder = client.prepareIndex("pethome", "user", "37");
Map<String, Object> map = new HashMap<>();
map.put("name"," New 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();
}Conditions of the query :
// The query user name contains zs,1 2 // Gender equals 0,1 2 // Age 18-80 year ,1 2 // Sort backwards by age , 1 2 // Take the second page , each page 10 strip 1 2
@Test
public void Estest(){
TransportClient client = getClient();
SearchRequestBuilder prepareSearch = client.prepareSearch("pethome");
prepareSearch.setTypes("user");
// Take the second page , each page 10 strip 1 2
prepareSearch.setFrom(1).setSize(5);
// Sort backwards by age , 1 2
prepareSearch.addSort("age",SortOrder.DESC);
BoolQueryBuilder query = QueryBuilders.boolQuery();
// The query user name contains zs,1
query.must(QueryBuilders.matchQuery("name","zs"));
// Age 18-80 year ,1
query.filter(QueryBuilders.rangeQuery("age").gte(18).lte(80));
// Gender equals 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());
}边栏推荐
- 2022 Yangtze River Delta industrial automation exhibition will be held in Nanjing International Exhibition Center in October
- 分家后印象笔记过日子依然不好过,骚操作却不少
- [spoken English] 01 - Introduction to atom
- es(1)
- Step by step introduction to the development framework based on sqlsugar (12) -- split the content of the page module into components to realize the division and rule processing
- 深入解析著名的阿里云Log4j 漏洞
- Common methods of number and math classes
- Memory allocation and recycling strategy
- C language to achieve a static version of the address book
- Array learning navigation
猜你喜欢

700. 二叉搜索树中的搜索-dfs法

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

Pay close attention! List of the latest agenda of 2022 open atom open source Summit

NPM install reported -4058 error

生信常用分析图形绘制02 -- 解锁火山图真谛!

es(1)

SV casts and constants

Array learning navigation

700. Search DFS method in binary search tree

ansible自动化运维详解(五)ansible中变量的设定使用、JINJA2模板的使用以及ansible的加密控制
随机推荐
Opencv picture rotation
awk从入门到入土(17)awk多行写法
Hcip fourth day notes
Openlayers: point aggregation effect
0623~放假自习
0621~ES&Lucene
Wrote a few small pieces of code, broke the system, and was blasted by the boss
C语言自定义类型讲解 — 联合体
阿里巴巴/1688按图搜索商品(拍立淘) API使用说明
0625~<config>-<bus>
Use 4D nerf to display occlusion (cvpr2022)
C # print reports using fastreport.net
MySQL数据库的一个问题
0616项目二结束~~总总结
0630~职业素养课
NPM install reported -4058 error
Review and analysis of noodle dishes
Shardingsphere database read / write separation
SV强制类型转换和常数
Dry goods | three sub domain name collection tools worth collecting