


# 创建索引
PUT /songs_v3
# 删除索引
DELETE /songs_v3
# 创建 index,指定 settings
PUT /songs_v4
{
"settings": {
"number_of_shards": 6,
"number_of_replicas": 1
}
}
# 获取 index 的 settings 信息
GET /songs_v4/_settings
# 修改 index 的配置信息
# index 的配置分为两类:
# static(number of shards/index.shard.check_on_startup)
# dynamic(index 正常工作时,能修改的配置信息)
PUT /songs_v4/_settings
{
"number_of_replicas": 2
}
# index 开启状态,不允许执行
PUT /songs_v4/_settings
{
"index.shard.check_on_startup": true
}
# 关闭 index
POST /songs_v4/_close
# 开启 index
POST /songs_v4/_open
# 获取 index 中的 mapping types
GET /songs_v4/_mapping
# 删除 mapping_type(不支持)
DELETE /songs_v4/_mapping# 索引文档
# 显示指定文档 ID
PUT /songs_v4/_doc/5
{
"songName": "could this be love",
"singer": "Jennifer Lopez",
"lyrics": "Could This Be love, work up This Morning Just..."
}
# 随机生成文档 ID
POST /songs_v4/_doc
{
"songName": "could this be love",
"singer": "Jennifer Lopez",
"lyrics": "Could This Be love, work up This Morning Just..."
}
# 更新文档
PUT /songs_v4/_doc/5
{
"songName": "could this be love",
"singer": "zp",
"lyrics": "Could This Be love, work up This Morning Just..."
}
# 根据 ID 明确查询某个文档
GET /songs_v4/_doc/5
# 根据 ID 删除文档
DELETE /songs_v4/_doc/5
# 搜索一个文档
GET /songs_v4/_search?q=singer:Jennifer
GET /songs_v4/_mapping# 创建 index 后,创建 mapping
PUT /books
PUT /books/_mapping
{
"properties": {
"bookName": {"type": "text"},
"content": {"type": "text"}
}
}
GET /books/_mapping
DELETE /books
# 创建 index,并指定 mapping
PUT /books
{
"mappings": {
"properties": {
"bookName": {"type": "text"},
"content": {"type": "text"}
}
}
}
GET /books/_mapping
DELETE /books
# 给 mapping 添加字段
PUT /books/_mappings
{
"properties": {
"author": {"type": "text"}
}
}
GET /books/_mapping官网描述:https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html
官网描述:https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-params.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-analyzers.html
PUT my_index
{
"mappings": {
"properties": {
"city": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
}
}
}
}PUT my_index/_doc/1
{
"city": "New York"
}
PUT my_index/_doc/2
{
"city": "York"
}GET my_index/_search
{
"query": {
"match": {
"city": "york"
}
},
"sort": [
{
"city.raw": {
"order": "asc"
}
}
],
"aggs": {
"citys": {
"terms": {
"field": "city.raw"
}
}
}
}PUT books
{
"mappings": {
"properties": {
"name": {"type": "text"},
"author": {"type": "text"},
"content": {"type": "text", "store": true}
},
"_source": {
"excludes": [
"content"
]
}
}
}字段名 | 说明 |
|---|---|
_index | 文档所属的 index |
_id | 文档的 id |
_type | 文档所属的 type |
_uid | _type#_id 的组合 |
_source | 文档的原生 json 字符串 |
_all | 自动组合所有的字段值,已过时 |
_field_names | 索引了每个字段的名称 |
_parent | 指定文档之间父子关系,已过时 |
_routing | 将一个文档根据路由存储到指定分片上 |
_meta | 用于自定义元数据 |
