ES入门命令

基本概念:

1. cluster 和 node

本质是分布式数据库。单个实例就是一个node,多个node构成一个cluster

2. Index

es会对索引所有的字段,处理后写入一个反向索引,类似于数据库。

查看当前所有节点的所有index

curl -X GET 'http://localhost:9200/_cat/indices?v'

3.Document

index里的单条记录称为document

例子如下:

{
  "user": "张三",
  "title": "工程师",
  "desc": "数据库管理"
}

4. type

index 下的分组称为type,多个type之间应该有相似的schema

查看某个index下的所有type

curl 'localhost:9200/_mapping?pretty=true'

基本操作

0. 修改用户密码

curl -X POST ‘http://localhost:9200/_xpack/security/user/jacknich/_password’ -d '
{
  "password" : "123456"
}'

1. 添加index

curl -X PUT 'localhost:9200/weather'

2. 删除index

curl -X DELETE 'localhost:9200/weather'

3.添加数据

put

curl -X PUT 'localhost:9200/accounts/person/1' -d '
{
  "user": "张三",
  "title": "工程师",
  "desc": "数据库管理"
}' 

上面的1表示此条数据id,如果不指定id,则需要使用post

post

curl -X POST 'localhost:9200/accounts/person' -d '
{
  "user": "李四",
  "title": "工程师",
  "desc": "系统管理"
}'

4. 查看数据

curl 'localhost:9200/accounts/person/1?pretty=true'

结果样例:

{
  "_index" : "accounts",
  "_type" : "person",
  "_id" : "1",
  "_version" : 1,
  "found" : true,
  "_source" : {
    "user" : "张三",
    "title" : "工程师",
    "desc" : "数据库管理"
  }
}

5. 修改记录

curl -X PUT 'localhost:9200/accounts/person/1' -d '
{
    "user" : "张三",
    "title" : "工程师",
    "desc" : "数据库管理,软件开发"
}' 

{
  "_index":"accounts",
  "_type":"person",
  "_id":"1",
  "_version":2,
  "result":"updated",
  "_shards":{"total":2,"successful":1,"failed":0},
  "created":false
}

6. 删除记录

curl -X DELETE 'localhost:9200/accounts/person/1'

7. 查询所有记录

curl 'localhost:9200/accounts/person/_search'

8. 全文搜索

普通搜索,desc字段里包含“软件”关键字

curl 'localhost:9200/accounts/person/_search'  -d '
{
  "query" : { "match" : { "desc" : "软件" }}
}'curl 'localhost:9200/accounts/person/_search'

指定记录条数

curl 'localhost:9200/accounts/person/_search'  -d '
{
  "query" : { "match" : { "desc" : "管理" }},
  "size": 1
}'

9. 逻辑运算

desc包含“软件” or “系统”

curl 'localhost:9200/accounts/person/_search'  -d '
{
  "query" : { "match" : { "desc" : "软件 系统" }}
}'

desc包含“软件” and “系统”

curl 'localhost:9200/accounts/person/_search'  -d '
{
  "query": {
    "bool": {
      "must": [
        { "match": { "desc": "软件" } },
        { "match": { "desc": "系统" } }
      ]
    }
  }
}'

1、ElasticSearch 官方手册

2、全文搜索引擎 Elasticsearch 入门教程 - 阮一峰的网络日志

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值