我在 Elasticsearch 中有一個物件,它可能包含不同的欄位。在我的應用程式中,此物件是 Enum,因此它實際上不能同時包含多個欄位。但是當我在 Elasticsearch 中進行更新時 - 它會附加欄位而不是覆寫整個物件。
例如 - 檔案可能是公開的或僅供一組用戶訪問:
POST _template/test_template
{
"index_patterns": [
"test*"
],
"template": {
"settings": {
"number_of_shards": 1
},
"mappings": {
"_source": {
"enabled": true
},
"properties": {
"id": {
"type": "keyword"
},
"users": {
"type": "object",
"properties": {
"permitted": {
"type": "keyword"
},
"public": {
"type": "boolean"
}
}
}
}
}
},
"aliases" : {
"test-alias" : { }
}
}
POST test_doc/_doc/1
{
"id": "1",
"users": {
"permitted": [
"1", "2"
]
}
}
POST _bulk
{"update":{"_index":"test_doc","_type":"_doc","_id":1}}
{"doc":{"id":"1","users":{"public": true}},"doc_as_upsert":true}
GET test-alias/_search
我期待這個結果:
{
"id": "1",
"users": {
"public": true
}
}
但實際結果是:
{
"id": "1",
"users": {
"permitted": [
"1",
"2"
],
"public": true
}
}
同時它完美地覆寫了具有相同名稱的欄位(我可以將允許的陣列或公共欄位更改為 false)。你如何禁用物件欄位附加?
uj5u.com熱心網友回復:
您需要將action批量請求更改為indexfrom update,正確的請求將是
{"index":{"_index":"71908768","_id":1}}
{"doc":{"id":"1","users":{"public": true}}}
請參閱官方 Elasticsearch 檔案中的操作及其詳細操作。簡而言之,update部分更新檔案,而索引操作索引指定檔案。如果檔案存在,則替換檔案并增加版本。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/463956.html
標籤:弹性搜索
上一篇:為什么彈性搜索會分析檔案2次?
