5.ES之documet的增删改查

1.创建doc指定ID

curl --location --request PUT '10.121.140.121:9200/nba/_doc/1' \
--header 'Content-Type: application/json' \
--data-raw '{
		"name":"六六",
		"country":"ZN",
		"position":"小前锋"
}'

2.获取指定的doc

curl --location --request GET '10.121.140.121:9200/nba/_doc/1'

3.更新doc

curl --location --request POST '10.121.140.121:9200/nba/_doc/1' \
--header 'Content-Type: application/json' \
--data-raw '{
		"name":"liuliu",
		"country":"ZN",
		"position":"小前锋1"
}'

4.查看多个doc

curl --location --request POST '10.121.140.121:9200/_mget' \
--header 'Content-Type: application/json' \
--data-raw '{
    "docs": [
        {
            "_index": "nba",
            "_type": "_doc",
            "_id": "1"
        },
        {
            "_index": "wnba",
            "_type": "_doc",
            "_id": "1"
        }
    ]
}'
说明:
_index 指定索引
_type: 指定doc
_id: 指定1 

5.查看dock指定index

curl --location --request POST '10.121.140.121:9200/nba/_mget' \
--header 'Content-Type: application/json' \
--data-raw '{
    "docs": [
        {
            "_type": "_doc",
            "_id": "1"
        },
        {
            "_type": "_doc",
            "_id": "2tz4NXIB0VrInUDwB_5N"
        }
    ]
}'

6.查看doc直接指定id

curl --location --request POST '10.121.140.121:9200/nba/_doc/_mget' \
--header 'Content-Type: application/json' \
--data-raw '{
	"ids":["1","2tz4NXIB0VrInUDwB_5N"]
}'

7.新增对应的字段

curl --location --request POST '10.121.140.121:9200/nba/_update/3NwANnIB0VrInUDw9_5L' \
--header 'Content-Type: application/json' \
--data-raw '{
    "script": "ctx._source.age=18"
}'

8.删除对应的字段

curl --location --request POST '10.121.140.121:9200/nba/_update/3NwANnIB0VrInUDw9_5L' \
--header 'Content-Type: application/json' \
--data-raw '{
    "script": "ctx._source.remove(\"age\")"
}'

9.根据参数值更新指定doc字段

curl --location --request POST '10.121.140.121:9200/nba/_update/1' \
--header 'Content-Type: application/json' \
--data-raw '{
	"script":{
		"source":"ctx._source.age += params.age",
		"params":{
			"age":4
		}
	},
	"upsert":{
		"age":1
	}
}'
说明:
假设没有age这个字段,就会默认赋予upsert.age这个值
假设有age字段,则这个值就会+params.age
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值