Elasticsearch里存储文档数据和关系型数据库MySQL存储数据的概念进行一个类比
注意:Elasticsearch 7.x版本中Type的概念已经被删除了。
1.REST请求操作Elasticsearch
创建索引 PUT
http://localhost:9200/索引名
#设置索引的分片和副本 { "settings": { "number_of_shards": 3, "number_of_replicas": 1 } }
查看指定索引 GET
http://localhost:9200/索引名
查看所有索引详细信息 GET
http://localhost:9200/_cat/indices?v
删除指定索引 DELETE
http://localhost:9200/索引名
创建文档 POST
http://localhost:9200/索引名/_doc/文档id 请求体携带JSON格式文档数据
查看指定文档 GET
http://localhost:9200/索引名/_doc/文档id
查看所有文档 GET
http://localhost:9200/索引名/_search
修改文档(完全覆盖修改) PUT
http://localhost:9200/索引名/_doc/文档id 请求体携带JSON格式文档数据
局部字段修改 POST
http://localhost:9200/索引名/_update/文档id
{ "doc":{ "字段名":"字段值" } }
删除指定文档 DELETE
http://localhost:9200/索引名/_doc/文档id
条件查询 GET
http://localhost:9200/suoyin1/_search
{ "query":{ "match":{ "字段名":"字段值" } } }