Elasticsearch如何索引现有的json文件

时间:2016-11-07 12:50:26

标签: elasticsearch

我使用 PUT 命令:

curl -PUT "http://localhost:9200/music/lyrics/2" --data-binary @D:\simple\caseyjones.json

caseyjones.json:

{
    "artist": "Wallace Saunders",
    "year": 1909,
    "styles": ["traditional"],
    "album": "Unknown",
    "name": "Ballad of Casey Jones",
    "lyrics": "Come all you rounders if you want to hear
            The story of a brave engineer
            Casey Jones was the rounder's name....
            Come all you rounders if you want to hear
            The story of a brave engineer
            Casey Jones was the rounder's name
            On the six-eight wheeler, boys, he won his fame
            The caller called Casey at half past four
            He kissed his wife at the station door
            He mounted to the cabin with the orders in his hand
            And he took his farewell trip to that promis'd land

            Chorus:
            Casey Jones--mounted to his cabin
            Casey Jones--with his orders in his hand
            Casey Jones--mounted to his cabin
            And he took his... land"
}

警告:无法解析,文档为空。但是log显示了* .json文件的内容。 Elasticsearch Screenshot

1 个答案:

答案 0 :(得分:0)

JSON不允许换行。因此,您需要使用\ n(特定于平台)替换所有换行符并将文本存储为单行。

像:

{
    "artist": "Wallace Saunders",
    "year": 1909,
    "styles": ["traditional"],
    "album": "Unknown",
    "name": "Ballad of Casey Jones",
    "lyrics": "Come all you rounders if you want to hear\nThe story of a brave engineer\nCasey Jones was the rounder's name...."
}