ElasticSearch6.x 之JSON 数据导入(Windows平台)分析

访客 阅读:263 2021-03-31 17:18:45 评论:0

第一步:注意事项

使用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 数据是否导入成功,执行如下命令。

声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

发表评论
搜索
KIKK导航

KIKK导航

排行榜
关注我们

一个IT知识分享的公众号