首先安裝 Elasticsearch和Kibana
Download Elasticsearch | Elastic Download Kibana Free | Get Started Now | Elastic
匯入相關maven依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
yml中配置相關引數
spring:
data:
elasticsearch:
cluster-name: elasticsearch
cluster-nodes: 127.0.0.1:9300 #9200是圖形界面端,9300代碼端
創建檔案物件
該檔案物件可用來做如下幾個事情
- 索引庫的創建
- 檔案的映射
- 存盤到ES的資料封裝
/**
* 針對于student表的檔案映射
* indexName:索引庫
* type:型別(表型別)
*/
@Document(indexName = "stu" , type = "student")
public class StudentDoc {
//對應檔案的id PUT /index/type/id
@Id
private Long id;
//指定為 不分詞
@Field(type = FieldType.Keyword)
private String userName;
private int age;
//指定為 分詞
@Field(type =FieldType.Text,analyzer = "ik_max_word",searchAnalyzer = "ik_max_word")
private String intro;
初始化索引庫和檔案映射
@RunWith(SpringRunner.class)
@SpringBootTest(classes = EsServiceApplication.class)
public class ElasticsearchTest {
@Autowired
private ElasticsearchTemplate elasticsearchTemplate;
@Test
public void testCreateIndex() {
//創建索引
elasticsearchTemplate.createIndex(StudentDoc.class);
//做檔案映射
elasticsearchTemplate.putMapping(StudentDoc.class);
}
}
到此為止基礎的集成就已經完成,可以通過Kibana測驗索引是否創建成功,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/423405.html
標籤:其他
上一篇:hive 學習筆記
下一篇:Gavin老師Transformer直播課感悟 - Rasa與ElasticSearch整合專案案例資料及配置作業機制與實踐及原始碼剖析(四十一)
