当前位置:网站首页>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());
}边栏推荐
- Class bytecode file
- 简单测试JS代码
- High performance complexity analysis of wechat circle of friends
- 05mysql lock analysis
- 阿里巴巴1688按关键字搜索商品 API 使用展示
- Array double pointer - deliberate practice
- 阿里巴巴/166获得店铺的所有商品 API使用说明
- C语言自定义类型讲解 — 结构体
- Brats18 - Multimodal MR image brain tumor segmentation challenge continued
- Development Series III of GaN (lapgan, srgan)
猜你喜欢

Review and analysis of noodle dishes

700. Search DFS method in binary search tree

In the morning, Tencent took out 38K, which let me see the ceiling of the foundation

Tensorflow introductory tutorial (40) -- acunet

Use Matplotlib to simulate linear regression

SV casts and constants

Df2net 3D model deployment

Array double pointer - deliberate practice

C language programming training topics: K characters in left-handed string, little Lele and Euclidean, printing arrow pattern, civil servant interview, poplar matrix

C语言自定义类型 — 枚举
随机推荐
What are the pitfalls from single architecture to distributed architecture?
Mobile robot (IV) four axis aircraft
Colleges and universities have introduced 23 Philippine doctors with heavy funds, and the relevant departments have launched an investigation!
Blackmagic Fusion Studio 18
ansible自动化运维详解(五)ansible中变量的设定使用、JINJA2模板的使用以及ansible的加密控制
Internship report 1 - face 3D reconstruction method
awk从入门到入土(19)awk扩展插件,让awk如虎添翼
Ipaylinks, a cross-border payment integration service, won the 3A Asia Award of treasury
Niuke linked list solution record
(mandatory) override equals must override hashcode (principle analysis)
Stream, file, IO
Quickly complete the unit test junit4 setting of intelij idea
Link editing tips of solo blog posts illegal links
《STL源码剖析》应该怎样读?
213. 打家劫舍 II-动态规划
How does win11 enhance the microphone? Win11 enhanced microphone settings
C language custom type explanation - structure
After separation, the impression notes are still difficult to live, but there are many coquettish operations
近30所高校,获教育部点名表扬!
Memory allocation and recycling strategy