初次使用ElasticSearch:基础命令
发布日期:2021-05-07 14:23:43 浏览次数:16 分类:技术文章

本文共 2082 字,大约阅读时间需要 6 分钟。

  • 安装

    $ docker pull docker.elastic.co/elasticsearch/elasticsearch:7.10.0 # 获取镜像$ docker run -d -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.10.0 # 启动单节点容器$ curl "127.0.0.1:9200" # 确认容器启动正常
  • 常用命令

  • 使用示例

    在中经常看到这样的介绍:

    GET /_cat/health?v

    翻译过来,实际使用中,是要在bash 命令行(以Linux为例) 中输入以下命令:

    curl -X GET localhost:9200/_cat/health?v

    其中localhost:9200指的是所安装的elasticsearch对外开放的接口。

    curl -X
    '
    ://
    :
    /
    ?
    ' -d ''

    <PATH> means the API endpoint.

  • Notions

    : a date and time from which a computer measures system time.

  • 命令解释

  • 状态管理
    • 查看节点状态

    the cat APIs return information about your cluster:

    GET /_cat/health?v

    查看index

    curl "localhost:9200/_cat/indices?v"
  • 存储数据
    • 存入数据
    curl -X PUT localhost:9200/customer/_doc/1?pretty -H 'Content-Type:application/json' -d '{"name":"Jonh Doe"}'

    customer : index

    _doc : type

    1 : unique document ID

    name : fileds

    • 向多个index写入数据
    curl -X POST "localhost:9200/_bulk?pretty" -H 'Content-Type: application/json' -d'{ "index" : { "_index" : "test", "_id" : "1" } }{ "field1" : "value1" }{ "delete" : { "_index" : "test", "_id" : "2" } }{ "create" : { "_index" : "test", "_id" : "3" } }{ "field1" : "value3" }{ "update" : {"_id" : "1", "_index" : "test"} }{ "doc" : {"field2" : "value2"} }'
    • 通过文件批量写入
    curl -H "Content-Type: application/json" -XPOST "localhost:9200/bank/_bulk?pretty&refresh" --data-binary "@accounts.json"
  • 查看数据
    • Information retrieve
    curl localhost:9200/customer/_doc/1?pretty
    • _search查询数据
    curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'{  "query": { "match_all": {} },  "sort": [    { "account_number": "asc" }  ]}'curl -XGET localhost:9200/bank/_search?pretty -H "Content-Type: application/json" -d '{"query":{"match":{"address":"mill lane"}}}'curl -XGET localhost:9200/bank/_search?pretty -H "Content-Type: application/json" -d '{"query":{"match_phrase":{"address":"mill lane"}}}'

    query : 查询

    match : 查询单词

    match_phrase : 查询短语

    match_all : 查询所有

    sort : 排序

    aggs:聚合分析

上一篇:初识PostgreSQL
下一篇:curl简介及各类参数介绍

发表评论

最新留言

感谢大佬
[***.8.128.20]2025年04月09日 03时27分15秒