Elastic Search常用命令

2022-09-12 12:22:59 浏览数 (1)

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

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.cn/149530.html原文链接:https://javaforall.cn

0 人点赞