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