Python 官方文档:入门教程 => 点击学习
接口幂等性 接口幂等性:数学概念,多次请求,相当于一次请求get,put,delete都是幂等性的接口post 存在幂等性的问题前端速度很快,点了两次,会生成两个订单用户在
1.es介绍10个点
2.安装
# 索引操作---》数据库操作---》新增,删除,修改,查询
# 1 新增索引:
PUT lqz2 # lqz2就是索引名字
{
"settings": {
"index":{
"number_of_shards":5,
"number_of_replicas":1
}
}
}
# 2 查询索引
GET lqz2/_settings
返回结果
{
"lqz2" : {
"settings" : {
"index" : {
"creation_date" : "1588822389842",
"number_of_shards" : "1",
"number_of_replicas" : "1",
"uuid" : "NBXIeVdHQ26vCuPn8_6uew",
"version" : {
"created" : "7050099"
},
"provided_name" : "lqz2"
}
}
}
}
# 3 更新索引
PUT lqz2/_settings
{
"number_of_replicas": 2
}
#4 删除lqz2索引
DELETE lqz2
#1 新增文档
POST lqz2/_doc/1
{
"title":"红楼梦",
"price":12,
"publish_addr":{
"province":"黑龙江",
"city":"鹤岗"
},
"publish_date":"2013-11-11",
"read_num":199,
"tag":["古典","名著"]
}
POST lqz2/_doc/2
{
"title":"西游记",
"price":22,
"publish_addr":{
"province":"上海",
"city":"上海"
},
"publish_date":"2013-11-11",
"read_num":66,
"tag":["古典","小说"]
}
# 2 查询文档(更详细的查找,后面讲)
GET lqz2/_doc/2
# 3 修改文档
-覆盖式(原来的字段就没有了)
PUT lqz/_doc/1
{
"title":"xxxx",
"price":333,
"publish_addr":{
"province":"黑龙江",
"city":"福州"
}
}
-增量式(只修改某个字段)一定要注意包在doc中
POST lqz2/_doc/1/_update
{
"doc":{
"title":"xx"
}
}
# 4 删除文档
DELETE lqz/_doc/1
# 5 批量获取
GET _mget
{
"docs":[
{
"_index":"lqz2",
"_type":"_doc",
"_id":2
},
{
"_index":"lqz2",
"_type":"_doc",
"_id":1
}
]
}
# 6 批量插入
PUT test/_doc/2/_create
{
"field1" : "value22"
}
POST _bulk
{ "index" : { "_index" : "test", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_id" : "2" } }
{ "create" : { "_index" : "test", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_index" : "test"} }
{ "doc" : {"field2" : "value2"} }
# 测试数据
PUT lqz/doc/1
{
"name":"顾老二",
"age":30,
"from": "gu",
"desc": "皮肤黑、武器长、性格直",
"tags": ["黑", "长", "直"]
}
PUT lqz/doc/2
{
"name":"大娘子",
"age":18,
"from":"sheng",
"desc":"肤白貌美,娇憨可爱",
"tags":["白", "富","美"]
}
PUT lqz/doc/3
{
"name":"龙套偏房",
"age":22,
"from":"gu",
"desc":"mmp,没怎么看,不知道怎么形容",
"tags":["造数据", "真","难"]
}
# 两种方式
-第一种(字符串查询)
GET lqz/doc/_search?q=from:gu
GET lqz/doc/_search?q=age:22
-查询的第二种方式(结构化)
GET lqz/doc/_search
{
"query": {
"match": {
"from": "gu"
}
}
}
GET lqz/doc/_search
{
"query": {
"match": {
"age": 22
}
}
}
GET lqz/doc/_search
{
"query": {
"match": {
"desc": "形容"
}
}
}
GET lqz/doc/_search
{
"query": {
"match": {
"tags": "造数据"
}
}
}
以上就是Elasticsearch文档索引基本操作增删改查示例的详细内容,更多关于Elasticsearch文档索引增删改查的资料请关注编程网其它相关文章!
--结束END--
本文标题: Elasticsearch文档索引基本操作增删改查示例
本文链接: https://lsjlt.com/news/117420.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0