
初次使用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
: type1
: unique document IDname
: 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
:聚合分析 -
发表评论
最新留言
感谢大佬
[***.8.128.20]2025年04月09日 03时27分15秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
医疗管理系统-手机快速登录和SpringSecurity权限控制
2019-03-04
vue源码分析(MVVM篇)
2019-03-04
React(八)- ReactUI组件库及Redux的使用
2019-03-04
TypeScript系列文章导航
2019-03-04
base64编码字符串和图片的互转
2019-03-04
linux 下安装kolla报错 提示Cannot uninstall requests
2019-03-04
设计模式之组合模式
2019-03-04
(Python学习笔记):字典
2019-03-04
(C++11/14/17学习笔记):线程启动、结束,创建线程多法、join,detach
2019-03-04
leetcode 14 最长公共前缀
2019-03-04
做做Java
2019-03-04
map的find函数和count函数
2019-03-04
C++并发与多线程(一)
2019-03-04
7628 EDCCA认证寄存器修改(认证自适应)
2019-03-04
计算机网络子网划分错题集
2019-03-04
java一些基本程序
2019-03-04
神经元与神经网络一之概述
2019-03-04
FANUC机器人R-30iB_R-30iB PLUS备件规格型号统计整理
2019-03-04
FANUC机器人的镜像备份操作及U盘格式化具体步骤
2019-03-04