Elastic Search常用命令

Elastic Search常用命令ES的基本指令:1. 查看es的集群状态:curl ‘IP:9200/_cat/health?v’注释:?v表示格式化输出2. 查看节点列表curl ‘IP:9200/_cat/nodes?v’3.查询所有索引及数据大小curl ‘IP:9200/_cat/indices?v’ 4.创建索引(名称为studentIndex)并指定分片数和备份数curl -XPUT http:/…

大家好,又见面了,我是你们的朋友全栈君。

ES的基本指令:
1. 查看es的集群状态:
curl ‘IP:9200/_cat/health?v’
注释:?v表示格式化输出
2. 查看节点列表
curl ‘IP:9200/_cat/nodes?v’
3.查询所有索引及数据大小
curl ‘IP:9200/_cat/indices?v’
 
4.创建索引(名称为studentIndex)并指定分片数和备份数
curl -XPUT http://localhost:9200/studentIndex -d’
{

    “settings” : {

        “index” : {

            “number_of_shards” : 3, 
            “number_of_replicas” : 2 
        }
    }
}’

5.创建索引studentIndex,并添加类型student,并指定分词是studentname
curl -XPUT ‘http://localhost:9200/studentIndex’ -d ‘
{

  “mappings”: {

    “student”: {

      “properties”: {

        “studentname”: {

          “type”: “string”
        }
      }
    }
  }
}’

ES和mysql的对应关系
MySql        ElasticSearch
database  — index
table        — type
row          — document
cloumn    — field
schema   — mapping
index       — Everything is indexed
slect * from…   — get http://…
update talbe set… — put http://…

6.查询索引是studentIndex,type是student,studentname字段的值是“李”的信息,默认返回第一页,10条数据

http://localhost:9200/studentIndex/student/_search?q=studentname:李

{

    “took”: 32,
    “timed_out”: false,
    “_shards”: {

        “total”: 5,
        “successful”: 5,
        “failed”: 0
    },
    “hits”: {

        “total”: 645161,
        “max_score”: 13.882782,
        “hits”: [{

                “_index”: “studentIndex”,
                “_type”: “student”,
                “_id”: “AWNIsqEX4aqkPyNgQr06”,
                “_score”: 13.882782,
                “_source”: {

                    “studentname”: “李李四”
                }
            },
            {

                “_index”: “studentIndex”,
                “_type”: “student”,
                “_id”: “AWNIsqEX4aqkPyNgQr06”,
                “_score”: 13.23425,
                “_source”: {

                    “studentname”: “李五”
                }
            }
        ]
    }
}

7.使用post查询elastic search

curl -X POST \
http://1ip:9200/studentIndex/student/_search 
  -d ‘{

    “query”: {

        “match”: {

            “studentname”: “李”
        }
    },
    “from”: 100,  // 第几页开始
    “size”: 10   // 每页的大小
}’

返回结果同上:

注释:
在url中的q=* 相等于body中的
{

    “query”: { “match_all”: {} }
  }

8.查询数据总数:http://localhost:9200/studentIndex/student/_count

9.
a.插入数据:
curl -X POST ‘localhost:9200/studentIndex/student?pretty’ -d’ {“studentname”: “Jane Doe” }’
b.指定数据的Id是id1
curl -X POST ‘localhost:9200/studentIndex/student/id1?pretty’ -d’ {“studentname”: “John Doe” }’
10 删除数据
a.删除studentIndex中ID为2的数据
curl -X DELETE ‘localhost:9200/studentIndex/student/2?pretty’

b.根据条件删除数据
curl -X POST ‘localhost:9200/studentIndex/student/_delete_by_query?pretty’ -d ‘{

    “query”: {

        “match”: {

            “studentname”: “John”
        }
    }
}’
11.
修改id=1的name属性,并直接增加属性和属性值
curl -X POST ‘localhost:9200/studentIndex/student/1/_update?pretty’ -d ‘ {

    “doc”: {

        “studentname”: “xyd” 
    }
}’

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/149530.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • java分页与排序orderby_mysql排序分页

    java分页与排序orderby_mysql排序分页java分页与排序代码如下不解释代码如下不解释publicclassSortObimplementsComparable{privateStringname;privateintage;privateDatecreateDate;publicSortOb(Stringname,intage,DatecreateDate){ this.name=name; this.age=age; this.createDate=createDate;}

    2022年10月3日
    4
  • 深入浅出MFC-读书笔记

    深入浅出MFC-读书笔记不想去成为一个伟大的程序员,只想成为一个具有良好习惯的优秀程序员。第一章:Win32基本程序观念我也赞同书中所讲,应用MFC框架开发Windows程序需要深入到底层,如果只停留在表面应用知其然而不知其所以然,这样会限制你更好的应用MFC框架。Win32程序开发流程下图说明一个32位WindowsSDK程序的开发流程:Windows程序分为…

    2022年6月16日
    33
  • phpstorm激活码2021.5.1[在线序列号]

    phpstorm激活码2021.5.1[在线序列号],https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月20日
    45
  • Mac WebServer、MySql安装、PHPAdmin安装

    Mac WebServer、MySql安装、PHPAdmin安装

    2021年9月1日
    84
  • char *string=”xxxxxxxxx” 与 char string[]=”xxxxx”的区别

    char *string=”xxxxxxxxx” 与 char string[]=”xxxxx”的区别char*string=”xxxxxx“这种方式使用的字面值模式,只读,不可以修改。string是个指针,这个字符串存放在程序的RODATA(read-only)段,不能修改的!表示你定义了一个字符指针,这个指针指向一个字符串常量,既然是常量那么通过这个指针修改这个常量是不可以的。charstring[]=”xxxxx”这种方式,字符串存储在数组

    2022年8月22日
    7
  • C语言小游戏之扫雷完整版

    C语言小游戏之扫雷完整版C语言小游戏之扫雷一.游戏介绍二.游戏步骤及实现的功能1.初始化雷盘2.打印雷盘3.随机布置雷4.玩家排雷5.防止玩家第一次被炸死6.统计所选位置周围八个位置中雷的个数7.拓展已选位置周围的区域8.标记雷及取消标记一.游戏介绍看到这张图片,相信很多小伙伴都非常熟悉,很多小伙伴都玩过扫雷这个小游戏,扫雷是一款益智类游戏,在放松娱乐的同时可以锻炼各位小伙伴的智商。游戏规则:如上图,玩家需要在不被炸死的前提下找出图中雷的位置,若能找出所有雷,则游戏胜利,若不幸踩到雷则被炸死。注:先介绍,后文会有完整代码

    2022年5月19日
    41

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号