es 7.0常用的命令

发布时间 2023-06-14 17:41:15作者: 乐之者v

es 7.0常用的命令

  • es新建索引:

格式:

PUT /索引名称
{
    "mappings":
	{
		"properties":{
			"字段名称":{
				"type":"字段类型"
			}
		}
	}
}

PUT 加索引名称 ,比如以下的 PUT /book_2023_09

type 表示字段类型。id、order_no 这些是字段名。

示例:

PUT /book_2023_09
{
    "mappings":
	{
		"properties":{
			"id":{
				"type":"long"
			},
			"order_no":{
				"type":"text"
			},
			"name":{
				"type":"keyword"
			},
			"create_date":{
				"type":"date"
			}

		}
	}
}
  • es 查询索引的字段结构/数据结构
GET /索引名称/_mapping
  • es 查询索引下面文档数量
GET /索引名称/_count
  • es 添加/更新别名:
PUT /索引名称/_alias/别名名称
  • es 查询别名:
GET /索引名称/_alias
  • es 新增文档:
POST /索引名称/_doc

示例:

POST /book_2020_09/_doc
{
  "name": "wu",
  "create_date": "2020-10-24",
  "order_no": "082313sfsd1",
  "id": 10823131
}
  • es 根据条件查询文档:
GET /book_2020_09/_search

详细的 查询见: https://www.cnblogs.com/expiator/p/13843957.html

  • es 根据_id查询文档:
GET /索引名称/_doc/文档的_id

注意:是 _search返回结果中的 _id, 而不是文档中的字段id。