第一步:注意事項
使用json文件可以給es中導入數據,10萬條左右的數據可以一次導入,數量太大時導入就會報錯。大數量的到導入還是需要用bulk方式。
第二步:創建website 索引,並且指定映射關係
編輯內容:
{
"settings": {
"number_of_replicas": 1,
"number_of_shards": 5
},
"mappings": {
"blog":{
"properties": {
"title":{
"type":"text",
"analyzer": "ik_max_word"
},
"author":{
"type":"text"
},
"postdate":{
"type":"date",
"format": "yyyy-MM-dd"
},
"abstract":{
"type":"text",
"analyzer": "ik_max_word"
},
"url":{
"type":"text"
}
}
}
}
}
第二步:文檔數據導入json文件(website.json)
{ "index":{"_id": "1" }}
{ "title": "ElasticSearch6.x 之IK 分詞","author":"周志剛","postdate":"2016-12-21","abstract":"ElasticSearch6.x 學習筆記","url":"https://blog.csdn.net/zhouzhiwengang/article/details/97112814"}
{ "index":{ "_id": "2" }}
{ "title": "ElasticSearch6.x 之字段類型","author":"周志剛","postdate":"2016-12-23","abstract":"ElasticSearch6.x 學習筆記","url":"https://blog.csdn.net/zhouzhiwengang/article/details/97099650"}
{ "index":{"_id": "3" }}
{ "title": "Spring-Security 控制用戶併發登入,並剔除前一個用戶","author":"周志剛","postdate":"2016-12-25","abstract":"Spring-Security 學習筆記","url":"https://blog.csdn.net/zhouzhiwengang/article/details/96164398"}
{ "index":{"_id": "4" }}
{ "title": "Spring-Security +Kaptcha 實現驗證碼功能","author":"周志剛","postdate":"2016-12-29","abstract":"Spring-Security 學習筆記","url":"https://blog.csdn.net/zhouzhiwengang/article/details/96155447"}
{ "index":{"_id": "5" }}
{ "title": "Spring JPA 用法總結","author":"周志剛","postdate":"2016-12-30","abstract":"Spring-JPA","url":"https://blog.csdn.net/zhouzhiwengang/article/details/96136417"}
{ "index":{"_id": "6" }}
{ "title": "Spring-Security 實現黑白名單功能","author":"周志剛","postdate":"2016-12-30","abstract":"Spring-Security 學習筆記","url":"https://blog.csdn.net/zhouzhiwengang/article/details/96134646"}
{ "index":{"_id": "7" }}
{ "title": "搭建Hadoop開發環境","author":"周志剛","postdate":"2016-12-30","abstract":"Hadoop 學習筆記","url":"https://blog.csdn.net/zhouzhiwengang/article/details/94616635"}
{ "index":{"_id": "8" }}
{ "title": "es高亮","author":"周志剛","postdate":"2017-01-03","abstract":"ElasticSearch6.x 學習筆記","url":"http://url/53991802"}
{ "index":{"_id": "9" }}
{ "title": "to be or not to be","author":"somebody","postdate":"2018-01-03","abstract":"to be or not to be,that is the question","url":"http://url/63991802"}
第三步:windows cmd 窗口模式,執行如下指令,進行本地json 數據導入es 中:
windows10下的curl需要先下載windows版的curl,再輸入命令:
curl -H "Content-Type: application/json" -XPOST 192.168.1.74:9200/website/blog/_bulk?pretty --data-binary "@C:\data\website.json"
含義解釋:H參數:指定請求頭的數據格式,-XPOST :post 請求, /website/blog:代表website 索引下類型爲blog data-binary:json 數據存儲地址。
第四步:驗證json 數據是否導入成功,執行如下命令。