2016-08-04 76 views
0

如果這是一個基本問題,我很抱歉,但這是我第一次與ES爭執。你如何找到並索引一個Json文件到ES中進行索引?如何在彈性搜索集羣中加載Json?

我已經看過ES文檔和類似於我的問題,但迄今爲止列出的所有方法都不適用於我。

Import/Index a JSON file into Elasticsearch

is there any way to import a json file(contains 100 documents) in elasticsearch server.?

我使用的是Mac OS和捲曲命令我使用_bulk我的JSON文件是這樣的:

curl -XPOST 'localhost:9200/bank/account/_bulk?pretty' --data-binary "@accounts.json" 

但是,這個錯誤彈出:

{ 
    "error": { 
    "root_cause": [ 
     { 
     "type": "parse_exception", 
     "reason": "Failed to derive xcontent" 
     } 
    ], 
    "type": "parse_exception", 
    "reason": "Failed to derive xcontent" 
    }, 
    "status": 400 
} 

回答

1

要使用批量api文件中的所有json對象s應該有這樣一行:

{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } } 

其中指定您的索引和類型名稱和文檔的id。

對於exmple含有以下內容將索引2個文件與索引=測試,類型= type1和ID = 1和2具有不同FIELD1值的文件:

{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } } 
{ "field1" : "value1" } 
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "2" } } 
{ "field1" : "value3" } 

然後就可以像運行一個命令:

curl -s -XPOST 'localhost:9200/_bulk' --data-binary "@accounts.json" 
+0

考慮到Json文件是直接從這個鏈接中的Elastic.co文檔頁面中看到的:它看起來已經是這種格式了:https://www.elastic.co/guide/en/elasticsearch/reference/current /_exploring_your_data.html – MLhacker

+0

爲防萬一它不是問題的位置,我已將json文件放在與elasticsearch.bat文件所在的目錄以及elasticsearch文件夾中的其他位置相同的目錄中,但似乎沒有解決這個問題。 – MLhacker

+0

elasticsearch日誌中的任何錯誤? – alpert

0

找出我錯了什麼。不要使用REST服務。從終端導入數據。

+0

你能詳細點嗎? –