Elasticsearch入门及REST API使用
官网查看更多API操作文档点击查看REST APIs文档
常用API
- 查看分词效果
POST /_analyzer
{
"analyzer": "ik_smart",
"text": "这是一个很长的句子"
}
- 跟踪集群分片出现Unassigned原因
GET /_cluster/allocation/explain
- 获取apiKey,expiration表示有效期,可不传即永久
POST /_security/api_key
{
"name": "my-api-key",
"expiration": "1d"
}
索引API
- 创建索引,可不带body,即最简单的Index
PUT /索引名称
{
"settings":{
"number_of_shards":3,
"number_of_replicas":2
},
"mappings": {
"properties": {
"id": {
"type": "long",
"store": true,
"index": false
},
"title": {
"type": "text",
"store": true,
"index": true,
"analyzer": "standard"
},
"content": {
"type": "text",
"store": true,
"index": true,
"analyzer": "standard"
}
}
}
}
- 删除索引
DELETE /索引名称
文档API
- 插入文档
PUT /索引名称/_doc/1
{
"id": 1,
"title": "打工人的觉悟",
"content": "副本分片,每一个分片有零个或多个副本。副本主要是主分片的复制,可以增加高可用性,提高性能。默认情况下,一个主分配有一个副本,但副本的数量可以在后面动态的配置增加。副本必须部署在不同的节点上,不能部署在和主分片相同的节点"
}
- 删除文档
DELETE /索引名称/_doc/1
- 查询文档
GET /索引名称/_search
{
"query": {
"match": {"content": "多个副本"}
}
}