2017-05-15 49 views
0

我想映射Elasticsearch上的JSON結構,但似乎是錯誤的,因爲當我從我的Windows提示符啓動curl命令沒有附加除了下劃線脈衝。無法加載JSON映射Elasticsearch

我使用curl命令:

curl -H "Content-Type: application/json" -XPUT http://localhost:9200/technogym -d "{\"mappings\":{\"id\":{\"type\":\"string\"},\"key\":{\"type\":\"string\"},\"value\":{\"type\":\"object\",\"properties\":{\"rev\":{\"type\":\"string\"}}},\"doc\":{\"type\":\"object\",\"properties\":{\"_id\":{\"type\":\"string\"},\"_rev\":{\"type\":\"string\"},\"userID\":{\"type\":\"string\"},\"conversation_id\":{\"type\":\"string\"},\"input\":{\"type\":\"object\",\"properties\":{\"text\":{\"type\":\"string\"}}},\"output\":{\"type\":\"object\",\"properties\":{\"text\":{\"type\":\"string\"}}},\"node_visited\":{\"type\":\"string\"},\"intents\":{\"properties\":{\"intent\":{\"type\":\"string\"},\"confidence\":{\"type\":\"string\"}}},\"entities\":{\"type\":\"object\",\"properties\":{\"entity\":{\"type\":\"string\"},\"location\":{\"type\":\"string\"},\"value\":{\"type\":\"string\"},\"confidence\":{\"type\":\"string\"}}},\"timestamp\":{\"type\":\"date\"}}}}}" 

這裏我jsonwith映射(只是爲了使其更具可讀性):

編輯

{"mappings": { 
"_default_": { 
    "properties": { 
    "id": { 
     "type": "string" 
    }, 
    "key": { 
     "type": "string" 
    }, 
    "value": { 
     "type": "object", 
     "properties": { 
     "rev": { 
      "type": "string" 
     } 
     } 
    }, 
    "doc": { 
     "type": "object", 
     "properties": { 
     "_id": { 
      "type": "string" 
     }, 
     "_rev": { 
      "type": "string" 
     }, 
     "userID": { 
      "type": "string" 
     }, 
     "conversation_id": { 
      "type": "string" 
     }, 
     "input": { 
      "type": "object", 
      "properties": { 
      "text": { 
       "type": "string" 
      } 
      } 
     }, 
     "output": { 
      "type": "object", 
      "properties": { 
      "text": { 
       "type": "string" 
      } 
      } 
     }, 
     "node_visited": { 
      "type": "string" 
     }, 
     "intents": { 
      "properties": { 
      "intent": { 
       "type": "string" 
      }, 
      "confidence": { 
       "type": "string" 
      } 
      } 
     }, 
     "entities": { 
      "type": "object", 
      "properties": { 
      "entity": { 
       "type": "string" 
      }, 
      "location": { 
       "type": "string" 
      }, 
      "value": { 
       "type": "string" 
      }, 
      "confidence": { 
       "type": "string" 
      } 
      } 
     }, 
     "timestamp": { 
      "type": "date" 
     } 
     } 
    } 
    } 
}}} 

我不知道爲什麼我能上傳這個映射。

感謝您的任何幫助。

回答

1

創建索引

curl -XPUT localhost:9200/technogym 
{"acknowledged":true} 

然後申請你映射到任何你想要的類型,例如。 technogym_type

curl -X PUT localhost:9200/technogym/technogym_type/_mapping -d '{ 
    "properties": { 
    "id": { 
     "type": "string" 
    }, 
    "key": { 
     "type": "string" 
    }, 
    "value": { 
     "type": "object", 
     "properties": { 
     "rev": { 
      "type": "string" 
     } 
     } 
    }, 
    "doc": { 
     "type": "object", 
     "properties": { 
     "_id": { 
      "type": "string" 
     }, 
     "_rev": { 
      "type": "string" 
     }, 
     "userID": { 
      "type": "string" 
     }, 
     "conversation_id": { 
      "type": "string" 
     }, 
     "input": { 
      "type": "object", 
      "properties": { 
      "text": { 
       "type": "string" 
      } 
      } 
     }, 
     "output": { 
      "type": "object", 
      "properties": { 
      "text": { 
       "type": "string" 
      } 
      } 
     }, 
     "node_visited": { 
      "type": "string" 
     }, 
     "intents": { 
      "properties": { 
      "intent": { 
       "type": "string" 
      }, 
      "confidence": { 
       "type": "string" 
      } 
      } 
     }, 
     "entities": { 
      "type": "object", 
      "properties": { 
      "entity": { 
       "type": "string" 
      }, 
      "location": { 
       "type": "string" 
      }, 
      "value": { 
       "type": "string" 
      }, 
      "confidence": { 
       "type": "string" 
      } 
      } 
     }, 
     "timestamp": { 
      "type": "date" 
     } 
     } 
    } 
    } 
}' 

{"acknowledged":true} 

但是,如果你要動態地創建索引和映射,剛修好你的JSON文件需要它mappings(複數),並隨後你想要的類型的名稱。 (類型相當於RDBMS表名)

curl -X PUT localhost:9200/technogym1 -d ' 
{ 
    "mappings": { 
    "technogym_type1": { 
     "properties": { 
     "id": { 
      "type": "string" 
     }, 
     "key": { 
      "type": "string" 
     }, 
     "value": { 
      "type": "object", 
      "properties": { 
      "rev": { 
       "type": "string" 
      } 
      } 
     }, 
     "doc": { 
      "type": "object", 
      "properties": { 
      "_id": { 
       "type": "string" 
      }, 
      "_rev": { 
       "type": "string" 
      }, 
      "userID": { 
       "type": "string" 
      }, 
      "conversation_id": { 
       "type": "string" 
      }, 
      "input": { 
       "type": "object", 
       "properties": { 
       "text": { 
        "type": "string" 
       } 
       } 
      }, 
      "output": { 
       "type": "object", 
       "properties": { 
       "text": { 
        "type": "string" 
       } 
       } 
      }, 
      "node_visited": { 
       "type": "string" 
      }, 
      "intents": { 
       "properties": { 
       "intent": { 
        "type": "string" 
       }, 
       "confidence": { 
        "type": "string" 
       } 
       } 
      }, 
      "entities": { 
       "type": "object", 
       "properties": { 
       "entity": { 
        "type": "string" 
       }, 
       "location": { 
        "type": "string" 
       }, 
       "value": { 
        "type": "string" 
       }, 
       "confidence": { 
        "type": "string" 
       } 
       } 
      }, 
      "timestamp": { 
       "type": "date" 
      } 
      } 
     } 
     } 
    } 
    } 
}' 
{"acknowledged":true,"shards_acknowledged":true} 
+1

謝謝;)。是的,我編輯了正確的JSON,因爲在我的右邊有一個「映射」而不是「映射」。感謝您的幫助,它已經成爲非常有用的 –

+1

偉大的,它爲你工作。如果您想先創建索引(相當於RDBMS中的數據庫名稱),然後鍵入映射,那麼請遵循第一個答案,否則您的做法也是正確的。您可以使用'http:// localhost:9200/technogym1/technogym_type1/_mapping?pretty = true'驗證映射 – prayagupd

1

您需要將mapping更改爲mappings

{ 
"mappings": {    ==> change this 
"_default_": { 
"properties": { 
"id": { 
    "type": "string" 
}, 
"key": { 
    "type": "string" 
}, 
"value": { 
    "type": "object", 
    "properties": { 
    "rev": { 
     "type": "string" 
    } 
    } 
}, 
"doc": { 
    "type": "object", 
    "properties": { 
    "_id": { 
     "type": "string" 
    }, 
    "_rev": { 
     "type": "string" 
    }, 
    "userID": { 
     "type": "string" 
    }, 
    "conversation_id": { 
     "type": "string" 
    }, 
    "input": { 
     "type": "object", 
     "properties": { 
     "text": { 
      "type": "string" 
     } 
     } 
    }, 
    "output": { 
     "type": "object", 
     "properties": { 
     "text": { 
      "type": "string" 
     } 
     } 
    }, 
    "node_visited": { 
     "type": "string" 
    }, 
    "intents": { 
     "properties": { 
     "intent": { 
      "type": "string" 
     }, 
     "confidence": { 
      "type": "string" 
     } 
     } 
    }, 
    "entities": { 
     "type": "object", 
     "properties": { 
     "entity": { 
      "type": "string" 
     }, 
     "location": { 
      "type": "string" 
     }, 
     "value": { 
      "type": "string" 
     }, 
     "confidence": { 
      "type": "string" 
     } 
     } 
    }, 
    "timestamp": { 
     "type": "date" 
     } 
     }}}}}} 
+0

對不起,您發佈了錯誤的json,但在我的右邊是映射。現在我編輯這個問題。謝謝 –