2016-08-04 46 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

你能详细点吗? –