• 替换
SQL REPLACE
REPLACE INTO table [(column1, column2, ...)]
VALUES (value1, value2, ...)
[, (...)]REPLACE INTO table
SET field1=value1[, ..., fieldN=valueN]
WHERE id = <id>JSON REPLACE
批量替换
最后更新于
REPLACE INTO table [(column1, column2, ...)]
VALUES (value1, value2, ...)
[, (...)]REPLACE INTO table
SET field1=value1[, ..., fieldN=valueN]
WHERE id = <id>最后更新于
POST /replace
{
"index": "<table name>",
"id": <document id>,
"doc":
{
"<field1>": <value1>,
...
"<fieldN>": <valueN>
}
}PUT/POST /<table name>/_doc/<id>
{
"<field1>": <value1>,
...
"<fieldN>": <valueN>
}POST /<{table | cluster:table}>/_update/<id>
{
"<field1>": <value1>,
...
"<fieldN>": <valueN>
}REPLACE INTO products VALUES(1, "document one", 10);Query OK, 1 row affected (0.00 sec)REPLACE INTO products SET description='HUAWEI Matebook 15', price=10 WHERE id = 55;Query OK, 1 row affected (0.00 sec)POST /replace
-H "Content-Type: application/x-ndjson" -d '
{
"index":"products",
"id":1,
"doc":
{
"title":"product one",
"price":10
}
}
'
{
"_index":"products",
"_id":1,
"created":false,
"result":"updated",
"status":200
}
PUT /products/_doc/2
{
"title": "product two",
"price": 20
}
POST /products/_doc/3
{
"title": "product three",
"price": 10
}{
"_id":2,
"_index":"products",
"_primary_term":1,
"_seq_no":0,
"_shards":{
"failed":0,
"successful":1,
"total":1
},
"_type":"_doc",
"_version":1,
"result":"updated"
}
{
"_id":3,
"_index":"products",
"_primary_term":1,
"_seq_no":0,
"_shards":{
"failed":0,
"successful":1,
"total":1
},
"_type":"_doc",
"_version":1,
"result":"updated"
}POST /products/_update/55
{
"doc": {
"description": "HUAWEI Matebook 15",
"price": 10
}
}{
"_index":"products",
"updated":1
}POST /cluster_name:products/_update/55
{
"doc": {
"description": "HUAWEI Matebook 15",
"price": 10
}
}{
"_index":"products",
"updated":1
}$index->replaceDocument([
'title' => 'document one',
'price' => 10
],1);Array(
[_index] => products
[_id] => 1
[created] => false
[result] => updated
[status] => 200
)indexApi.replace({"index" : "products", "id" : 1, "doc" : {"title" : "document one","price":10}}){'created': False,
'found': None,
'id': 1,
'index': 'products',
'result': 'updated'}res = await indexApi.replace({"index" : "products", "id" : 1, "doc" : {"title" : "document one","price":10}});{"_index":"products","_id":1,"result":"updated"}docRequest = new InsertDocumentRequest();
HashMap<String,Object> doc = new HashMap<String,Object>(){{
put("title","document one");
put("price",10);
}};
docRequest.index("products").id(1L).setDoc(doc);
sqlresult = indexApi.replace(docRequest);class SuccessResponse {
index: products
id: 1
created: false
result: updated
found: null
}
Dictionary<string, Object> doc = new Dictionary<string, Object>();
doc.Add("title", "document one");
doc.Add("price", 10);
InsertDocumentRequest docRequest = new InsertDocumentRequest(index: "products", id: 1, doc: doc);
var sqlresult = indexApi.replace(docRequest);class SuccessResponse {
index: products
id: 1
created: false
result: updated
found: null
}
res = await indexApi.replace({
index: 'test',
id: 1,
doc: { content: 'Text 11', name: 'Doc 11', cat: 3 },
});{
"_index":"test",
"_id":1,
"created":false
"result":"updated"
"status":200
}replaceDoc := map[string]interface{} {"content": "Text 11", "name": "Doc 11", "cat": 3}
replaceRequest := manticoreclient.NewInsertDocumentRequest("test", replaceDoc)
replaceRequest.SetId(1)
res, _, _ := apiClient.IndexAPI.Replace(context.Background()).InsertDocumentRequest(*replaceRequest).Execute(){
"_index":"test",
"_id":1,
"created":false
"result":"updated"
"status":200
}REPLACE INTO products(id,title,tag) VALUES (1, 'doc one', 10), (2,' doc two', 20);Query OK, 2 rows affected (0.00 sec)POST /bulk
-H "Content-Type: application/x-ndjson" -d '
{ "replace" : { "index" : "products", "id":1, "doc": { "title": "doc one", "tag" : 10 } } }
{ "replace" : { "index" : "products", "id":2, "doc": { "title": "doc two", "tag" : 20 } } }
'{
"items":
[
{
"replace":
{
"_index":"products",
"_id":1,
"created":false,
"result":"updated",
"status":200
}
},
{
"replace":
{
"_index":"products",
"_id":2,
"created":false,
"result":"updated",
"status":200
}
}
],
"errors":false
}$index->replaceDocuments([
[
'id' => 1,
'title' => 'document one',
'tag' => 10
],
[
'id' => 2,
'title' => 'document one',
'tag' => 20
]
);Array(
[items] =>
Array(
Array(
[_index] => products
[_id] => 2
[created] => false
[result] => updated
[status] => 200
)
Array(
[_index] => products
[_id] => 2
[created] => false
[result] => updated
[status] => 200
)
)
[errors => false
)indexApi = manticoresearch.IndexApi(client)
docs = [ \
{"replace": {"index" : "products", "id" : 1, "doc" : {"title" : "document one"}}}, \
{"replace": {"index" : "products", "id" : 2, "doc" : {"title" : "document two"}}} ]
api_resp = indexApi.bulk('\n'.join(map(json.dumps,docs))){'error': None,
'items': [{u'replace': {u'_id': 1,
u'_index': u'products',
u'created': False,
u'result': u'updated',
u'status': 200}},
{u'replace': {u'_id': 2,
u'_index': u'products',
u'created': False,
u'result': u'updated',
u'status': 200}}]}
docs = [
{"replace": {"index" : "products", "id" : 1, "doc" : {"title" : "document one"}}},
{"replace": {"index" : "products", "id" : 2, "doc" : {"title" : "document two"}}} ];
res = await indexApi.bulk(docs.map(e=>JSON.stringify(e)).join('\n'));{"items":[{"replace":{"_index":"products","_id":1,"created":false,"result":"updated","status":200}},{"replace":{"_index":"products","_id":2,"created":false,"result":"updated","status":200}}],"errors":false}
body = "{\"replace\": {\"index\" : \"products\", \"id\" : 1, \"doc\" : {\"title\" : \"document one\"}}}" +"\n"+
"{\"replace\": {\"index\" : \"products\", \"id\" : 2, \"doc\" : {\"title\" : \"document two\"}}}"+"\n" ;
indexApi.bulk(body);class BulkResponse {
items: [{replace={_index=products, _id=1, created=false, result=updated, status=200}}, {replace={_index=products, _id=2, created=false, result=updated, status=200}}]
error: null
additionalProperties: {errors=false}
}string body = "{\"replace\": {\"index\" : \"products\", \"id\" : 1, \"doc\" : {\"title\" : \"document one\"}}}" +"\n"+
"{\"replace\": {\"index\" : \"products\", \"id\" : 2, \"doc\" : {\"title\" : \"document two\"}}}"+"\n" ;
indexApi.Bulk(body);class BulkResponse {
items: [{replace={_index=products, _id=1, created=false, result=updated, status=200}}, {replace={_index=products, _id=2, created=false, result=updated, status=200}}]
error: null
additionalProperties: {errors=false}
}replaceDocs = [
{
replace: {
index: 'test',
id: 1,
doc: { content: 'Text 11', cat: 1, name: 'Doc 11' },
},
},
{
replace: {
index: 'test',
id: 2,
doc: { content: 'Text 22', cat: 9, name: 'Doc 22' },
},
},
];
res = await indexApi.bulk(
replaceDocs.map((e) => JSON.stringify(e)).join("\n")
);{
"items":
[
{
"replace":
{
"_index":"test",
"_id":1,
"created":false,
"result":"updated",
"status":200
}
},
{
"replace":
{
"_index":"test",
"_id":2,
"created":false,
"result":"updated",
"status":200
}
}
],
"errors":false
}body := "{\"replace\": {\"index\": \"test\", \"id\": 1, \"doc\": {\"content\": \"Text 11\", \"name\": \"Doc 11\", \"cat\": 1 }}}" + "\n" +
"{\"replace\": {\"index\": \"test\", \"id\": 2, \"doc\": {\"content\": \"Text 22\", \"name\": \"Doc 22\", \"cat\": 9 }}}" +"\n";
res, _, _ := apiClient.IndexAPI.Bulk(context.Background()).Body(body).Execute(){
"items":
[
{
"replace":
{
"_index":"test",
"_id":1,
"created":false,
"result":"updated",
"status":200
}
},
{
"replace":
{
"_index":"test",
"_id":2,
"created":false,
"result":"updated",
"status":200
}
}
],
"errors":false
}