es7.5.1 crud

官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html
1.创建people索引
put http://localhost:9200/people

{
	"settings":{
		"number_of_shards":3,
		"number_of_replicas":1
	},	
	"mappings":{
			"properties":{
				"name":{
					"type":"text"
				},
				"country":{
					"type":"keyword"
				},
				"age":{
					"type":"integer"
				},
				"date":{
					"type":"date",
					"format":"yyyy-MM-dd HH:mm:ss || yyyy-MM-dd || epoch_millis"
				}
			}
		}
	
}

返回

{"acknowledged":true,"shards_acknowledged":true,"index":"people"}

2.添加一条记录
POST http://localhost:9200/people/_doc

{
	"name":"guoy",
	"country":"china",
	"age":28,
	"date":"2019-04-19"
}

查询
POST http://localhost:9200/people/_doc/1/

{
	"name":"niurj",
	"country":"china",
	"age":28,
	"date":"2019-04-19"
}

或者
http://localhost:9200/book/_search

{
  "query": {
    "match": {
      "author": "小花"
    }
  }
}

3.更新
post http://localhost:9200/people/_doc/1/_update


{
	"script":{
		"lang":"painless",
		"inline":"ctx._source.age += 10"
	}
}

或者

{
	"script":{
		"lang":"painless",
		"inline":"ctx._source.age = params.age",
		"params":{
			"age":99
		}
	}
}

4.删除一条数据
delete http://localhost:9200/people/_doc/1
返回

{"_index":"people","_type":"_doc","_id":"1","_version":6,"result":"deleted","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":5,"_primary_term":1}

或者 查询删除
POST http://localhost:9200/book/_delete_by_query

{
  "query": {
    "match": {
      "author": "小葡萄"
    }
  }
}

5.删除一个索引
delete http://localhost:9200/people
返回

{"acknowledged":true}

6.高级查询
6.1创建索引book
put http://localhost:9200/book

{
	"settings":{
		"number_of_shards":3,
		"number_of_replicas":1
	},
	
	"mappings":{
		
			"properties":{
				"word_count":{
					"type":"integer"
				},
				"author":{
					"type":"keyword"
				},
				"title":{
					"type":"text"
				},
				"publish_date":{
					"type":"date",
					"format":"yyyy-MM-dd HH:mm:ss || yyyy-MM-dd || epoch_millis"
				}
			}
		
	}
}

插入一条数据
PUT http://localhost:9200/book/_doc/1

{
  "word_count":1000,
"author":"小葡萄",
"title":"调皮捣蛋",
"public_date":"2020-01-20"
}

6.2请求体查询
获取集群中所有的索引
get http://localhost:9200/_all
老版本:_search
返回

{
	"book": {
		"aliases": {},
		"mappings": {
			"properties": {
				"author": {
					"type": "keyword"
				},
				"public_date": {
					"type": "date"
				},
				"publish_date": {
					"type": "date",
					"format": "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd || epoch_millis"
				},
				"title": {
					"type": "text"
				},
				"word_count": {
					"type": "integer"
				}
			}
		},
		"settings": {
			"index": {
				"creation_date": "1579511120979",
				"number_of_shards": "3",
				"number_of_replicas": "1",
				"uuid": "kGNK0FFFRyu1CjvsDXa7wQ",
				"version": {
					"created": "7050199"
				},
				"provided_name": "book"
			}
		}
	},
	"mc": {
		"aliases": {},
		"mappings": {
			"properties": {
				"age": {
					"type": "long"
				},
				"interests": {
					"type": "text",
					"fields": {
						"keyword": {
							"type": "keyword",
							"ignore_above": 256
						}
					}
				},
				"name": {
					"type": "text",
					"fields": {
						"keyword": {
							"type": "keyword",
							"ignore_above": 256
						}
					}
				}
			}
		},
		"settings": {
			"index": {
				"creation_date": "1577696612860",
				"number_of_shards": "1",
				"number_of_replicas": "1",
				"uuid": "vHQOchJQTlWdW-fcqmDwAQ",
				"version": {
					"created": "7050199"
				},
				"provided_name": "mc"
			}
		}
	},
	"people": {
		"aliases": {},
		"mappings": {
			"properties": {
				"age": {
					"type": "integer"
				},
				"country": {
					"type": "keyword"
				},
				"date": {
					"type": "date",
					"format": "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd || epoch_millis"
				},
				"name": {
					"type": "text"
				}
			}
		},
		"settings": {
			"index": {
				"creation_date": "1579510580371",
				"number_of_shards": "3",
				"number_of_replicas": "1",
				"uuid": "-X8sxwteRMmXfhLQ17wiWA",
				"version": {
					"created": "7050199"
				},
				"provided_name": "people"
			}
		}
	}
}

查看多个索引以逗号分隔支持表达式
GET http://localhost:9200/book,p*
返回 可以看到返回了book索引和people索引

{
	"book": {
		"aliases": {},
		"mappings": {
			"properties": {
				"author": {
					"type": "keyword"
				},
				"public_date": {
					"type": "date"
				},
				"publish_date": {
					"type": "date",
					"format": "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd || epoch_millis"
				},
				"title": {
					"type": "text"
				},
				"word_count": {
					"type": "integer"
				}
			}
		},
		"settings": {
			"index": {
				"creation_date": "1579511120979",
				"number_of_shards": "3",
				"number_of_replicas": "1",
				"uuid": "kGNK0FFFRyu1CjvsDXa7wQ",
				"version": {
					"created": "7050199"
				},
				"provided_name": "book"
			}
		}
	},
	"people": {
		"aliases": {},
		"mappings": {
			"properties": {
				"age": {
					"type": "integer"
				},
				"country": {
					"type": "keyword"
				},
				"date": {
					"type": "date",
					"format": "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd || epoch_millis"
				},
				"name": {
					"type": "text"
				}
			}
		},
		"settings": {
			"index": {
				"creation_date": "1579510580371",
				"number_of_shards": "3",
				"number_of_replicas": "1",
				"uuid": "-X8sxwteRMmXfhLQ17wiWA",
				"version": {
					"created": "7050199"
				},
				"provided_name": "people"
			}
		}
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值