索引基本操作
1.新建索引
PUT employees
2.新建mapping
POST /employees/_doc/_mapping
{
"properties": {
"birth_date": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"emp_no": {
"type": "long"
},
"first_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"gender": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"hire_date": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"last_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
3.精确查询
GET /app/_doc/166
4.根据时间段查询
GET /app/_search
{
"size": 1,
"query": {
"bool": {
"must": [
{"range": {
"collect_time": {
"gte": "2020-06-01-20",
"lte": "2020-06-01-21",
"format": "yyyy-MM-dd-HH",
"time_zone":"+08:00"
}
}
}
]
}
}
}
1.查询全部数据
GET /test/_search
2.查询指定字段
GET /test/_search
{
"query": {
"match_all": {}
},
"_source": ["title","age"]
}
es集群操作
1.查看集群健康状态
curl -XGET 'http://localhost:9200/_cluster/health?pretty'
2.查看主节点
curl -XGET 'http://localhost:9200/_cluster/state/master_node,nodes?pretty'
3.停用集群中的节点
curl -XPUT http://localhost:9200/_cluster/settings -d '{
"transient" : {
"cluster.routing.allocation.exclude._ip" : "10.102.29.69"
}
}'
4.确定分片位置
curl -XGET 'http://localhost:9200/_cluster/state/routing_table,routing_nodes?pretty'
5.为索引创建别名
POST _aliases
{
"actions" : [{"add" : {"index" : "school" , "alias" : "in1"}}]
}
6.删除别名
POST _aliases
{
"actions" : [{"remove" : {"index" : "school" , "alias" : "in1"}}]
}
搜索数据
1.请求范围
/_search 全局搜索
/索引名/_search 根据索引搜索
/索引名/类型/_serach
/_all/类型/_search
/*/类型/_search
/索引1,索引2/类型1,类型2/_serach
2.###################基于URL的搜索######################
GET /app/_search?from=10&size=10
GET /app/_search?sort=collect_time:desc
GET /app/_search?sort=collect_time:desc&_source=ip,collect_time
GET /app/_search?sort=collect_time:desc&q=type:lettuce