2015-08-31 28 views
2

我有一個json文檔,我想索引。JSON文件未能索引

但是,當我嘗試索引文件,我總是得到一個錯誤。命名file.json

{ 
    "_index": "myIndex", 
    "_type": "myType", 
    "_id": "p1486f499782beb828d870f4a92831720e048514f", 
    "_score": 14.609365, 
    "_source": { 
    "content": "When we hear the word summer we think of beaches, sun tans and tiny bikinis. What we ", 
    "source": "hello.com", 
    "type": "sports", 
    "guid": "p1486f499782beb828d870f4a92831720e048514f", 
    "language": "en" 
    } 
} 

我試圖索引像這樣JSON文件---

curl -XPOST 'localhost:9200/myIndex/myType' -d @file.json 

{ 「錯誤」

我的JSON文件---「RemoteTransportException [ [Klaatu] [inet [/ 192.168.1.127:9300]] [indices:data/write/index]]; 嵌套:MapperParsingException [未解析,文檔爲空]; 「,」status「:400}

我還試圖像這樣----

curl -s -XPOST localhost:9200/_bulk --data-binary @file.json 

{ 「錯誤」: 「ElasticsearchParseException [未能得到 xcontent]」, 「狀態」:400}

如何索引我的文檔,任何人都知道如何解決這個問題!

回答

2

首先確保您的file.json只包含_source內容,而不是_index_type,等於是在file.json您應該只有這一點:

{ 
    "content": "When we hear the word summer we think of beaches, sun tans and tiny bikinis. What we ", 
    "source": "hello.com", 
    "type": "sports", 
    "guid": "p1486f499782beb828d870f4a92831720e048514f", 
    "language": "en" 
} 

然後你可以索引像這樣

curl -XPOST 'localhost:9200/myIndex/myType/p1486f499782beb828d870f4a92831720e048514f' --data-binary @file.json 

如果你想使用_bulk endpoint那麼你file.json需要略有不同:

{"index":{"_index":"myIndex", "_type":"myType", "_id": "p1486f499782beb828d870f4a92831720e048514f"}} 
{"content": "When we hear the word summer we think of beaches, sun tans and tiny bikinis. What we ", "source": "hello.com", "type": "sports", "guid": "p1486f499782beb828d870f4a92831720e048514f", "language": "en" } 

注意:確保使用換行符結束文件。換行符不會出現在上面的例子中。

然後你就可以像這樣

curl -XPOST 'localhost:9200/_bulk' --data-binary @file.json 

發送因此,底線是,通過文件發送文檔內容時,你需要使用的--data-binary代替-d

+0

@Great :)非常感謝Val :),它的工作原理就像你解釋過的:) –