簡體   English   中英

Elasticsearch 將文檔字段值從整數更新為字符串

[英]Elasticsearch update document field value from interger to string

我有一個彈性搜索索引,其中一個字段與關鍵字的數據類型映射,這意味着字段將接受所有數據類型因此,我已將字符串和 integer 值接收到彈性搜索索引的同一字段中

現在,我想將所有 integer 值更新為字符串

例如:文件

{
    "_index": "my-index",
    "_type": "my_index_doc",
    "_id": "PqLbOW4BtJ-51rS9hMsm",
    "_score": null,
    "_source": {
        "user_id": 1019407,
    },
    "sort": [
        1572928717850
    ]
}

所以我想將 user_id 字段為 integer 的所有文檔數據更改為字符串,如下所示

預期文件:

{
    "_index": "my-index",
    "_type": "my_index_doc",
    "_id": "PqLbOW4BtJ-51rS9hMsm",
    "_score": null,
    "_source": {
        "user_id": "1019407",
    },
    "sort": [
        1572928717850
    ]
},

我們可以對所有文檔/任何其他解決方案使用彈性搜索更新查詢嗎?

如有錯誤請見諒。

提前致謝

您可以利用查詢更新 API來實現此目的。 簡單地運行這個:

POST my-index/_update_by_query
{
  "script": {
    "source": "ctx._source.user_id = Integer.toString(ctx._source.user_id);",
    "lang": "painless"
  },
  "query": {
    "match_all": {}
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM