簡體   English   中英

使用curl遷移elasticsearch映射

[英]Migrate elasticsearch mapping with curl

我想通過將映射的輸出管道化為curl來使用curl遷移索引的elasticsearch映射。

目的是為另一個主機上的索引遷移或創建映射。

現在,我運行以下命令:

curl -X GET "http://$SOURCE_HOSTNAME:9200/$SOURCE_INDEX/_mapping?pretty" | curl -X PUT "http://$DESTINATION_HOSTNAME:9200/$DESTINATION_INDEX/_mapping?pretty" -H 'Content-Type: application/json' -d "$(</dev/stdin)"

但是我收到以下錯誤。

{
  "error" : {
    "root_cause" : [
      {
        "type" : "action_request_validation_exception",
        "reason" : "Validation Failed: 1: mapping type is missing;"
      }
    ],
    "type" : "action_request_validation_exception",
    "reason" : "Validation Failed: 1: mapping type is missing;"
  },
  "status" : 400
}

此處聲稱正確的輸出缺少映射類型,這似乎很奇怪。

直接從json文件讀取時發生相同的問題

有兩個問題。 第一個是您從GET $SOURCE_INDEX/_mapping調用中獲得的結果包含映射,但是它包裝在另一個名為源索引的屬性中。

例如, GET _mapping調用將返回以下內容:

{
   "your_index_name": {     <--- your mapping is wrapped within the source index name
      "mappings": {         <--- and also within the mappings structure
         "doc": {           <--- this is the structure you need when hitting the _mapping endpoint
            ...
         }
      }
   }
}

第二個問題是您的目標URL缺少映射類型名稱,即應為$DESTINATION_INDEX/_mapping/$SOME_TYPE

因此,您需要:

  1. 在目標URL中指定映射類型
  2. 一種解開從源索引中獲得的信息的方法。 您可以輕松地使用(例如) jq來執行此操作

暫無
暫無

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

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