es教程(一)

作者: 睦月MTK | 来源:发表于2019-11-25 14:24 被阅读0次

@snmutsuki
参考文档

适用于7.4版本!命令运行在powershell下

一、启动es
  • 一个es簇由一个至多个节点组成,一个ip下的es节点会自动加入到一个es簇中去

    $ elasticsearch -E path.data=\data\es\data0 -E path.logs=\data\es\log0
    $ elasticsearch -E path.data=\data\es\data1 -E path.logs=\data\es\log1
    
  • 查看es簇的情况信息

    $ curl.exe -X GET "localhost:9200/_cat/health?v&pretty"
    
二、索引文档
  • 添加篇文档到customer索引的_doc类型下[1]
$ curl.exe -X PUT "localhost:9200/customer/_doc/1?pretty" `
-H "Content-Type:application/json" -d '{
 \"name\":\"john\"
}'
  • 查看刚刚添加的文档

    $ curl -X GET "localhost:9200/customer/_doc/1?pretty"
    
  • 一次性添加大量文件

    1. 将需要写的数据放入一个json格式的文件中,注意文件必须以一个空行结束!

      {"index":{"_id":"1"}}
      {"account_number":1,"balance":39225,"firstname":"Amber","lastname":"Duke","age":32,"gender":"M","address":"880 Holmes Lane","employer":"Pyrami","email":"amberduke@pyrami.com","city":"Brogan","state":"IL"}
      ...
      
    2. 使用--data-binary "@文件名.json"绑定需要传输的数据

      $ curl.exe -H "Content-Type: application/json" `
      -X POST "localhost:9200/bank/_bulk?pretty&refresh" `
      --data-binary "@<路径>account.json"
      
    3. 查看es下各个索引的情况

    $ curl.exe -X GET "localhost:9200/_cat/indices?v&pretty"
    health status index    uuid                   pri rep docs.count docs.deleted store.size pri.store.size
    yellow open   bank     2_KSF7fUTu6ao_B_XdMVbg   1   1       1000            0    414.3kb        414.3kb
    yellow open   customer BLGw9U6aSGSGsCGjU75SqA   1   1          1            0      3.5kb          3.5kb
    

附:
[1] account.json


  1. 低版本es可能不支持type的名字以下划线开头,务必去除

相关文章

网友评论

    本文标题:es教程(一)

    本文链接:https://www.haomeiwen.com/subject/wbodwctx.html