每次我按照弹性搜索中的创建索引,映射和添加数据的说明我都有错误。 我正在使用邮递员。 首先,我创建索引:
POST http://localhost:9200/schools
(实际上,我必须使用put来成功创建)
接下来,我创建映射和添加数据:
POST http://localhost:9200/schools/_bulk
请求正文
{
"index":{
"_index":"schools", "_type":"school", "_id":"1"
}
}
{
"name":"Central School", "description":"CBSE Affiliation", "street":"Nagan",
"city":"paprola", "state":"HP", "zip":"176115", "location":[31.8955385, 76.8380405],
"fees":2000, "tags":["Senior Secondary", "beautiful campus"], "rating":"3.5"
}
{
"index":{
"_index":"schools", "_type":"school", "_id":"2"
}
}
{
"name":"Saint Paul School", "description":"ICSE
Afiliation", "street":"Dawarka", "city":"Delhi", "state":"Delhi", "zip":"110075",
"location":[28.5733056, 77.0122136], "fees":5000,
"tags":["Good Faculty", "Great Sports"], "rating":"4.5"
}
{
"index":{"_index":"schools", "_type":"school", "_id":"3"}
}
{
"name":"Crescent School", "description":"State Board Affiliation", "street":"Tonk Road",
"city":"Jaipur", "state":"RJ", "zip":"176114","location":[26.8535922, 75.7923988],
"fees":2500, "tags":["Well equipped labs"], "rating":"4.5"
}
但我收到的只是:
{
"error": {
"root_cause": [
{
"type": "json_e_o_f_exception",
"reason": "Unexpected end-of-input: expected close marker for Object (start marker at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@681c6189; line: 1, column: 1])\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@681c6189; line: 2, column: 3]"
}
],
"type": "json_e_o_f_exception",
"reason": "Unexpected end-of-input: expected close marker for Object (start marker at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@681c6189; line: 1, column: 1])\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@681c6189; line: 2, column: 3]"
},
"status": 500
}
答案 0 :(得分:5)
这是因为您的请求正文JSON格式错误。我建议只检查一个条目,直到你可以进入Elasticsearch,然后添加其他条目。
以下JSON是有效的,但我不确定它是否提供了您想要的结构:
{
"index":{
"_index":"schools", "_type":"school", "_id":"1"
},
"name":"Central School", "description":"CBSE Affiliation", "street":"Nagan",
"city":"paprola", "state":"HP", "zip":"176115", "location":[31.8955385, 76.8380405],
"fees":2000, "tags":["Senior Secondary", "beautiful campus"], "rating":"3.5"
}
您可以使用工具格式化和验证JSON,以确保它是有效的JSON。以下是一些例子。
答案 1 :(得分:0)
我看到的东西与我的问题类似。我的问题解决了!
Elasticsearch Bulk API - Unexpected end-of-input: expected close marker for ARRAY
答案 2 :(得分:0)
RecyclerView
答案 3 :(得分:0)
要将数据加载到Elasticsearch,请使用REST API端点为'/ _bulk' 以下换行符分隔的JSON(NDJSON)结构:
action_and_meta_data\n
optional_source\n
....
action_and_meta_data\n
optional_source\n
卷曲请求示例: curl -H'内容类型:application / x-ndjson'-XPOST'elasticsearchhost:port / index-name-sample / _bulk?pretty'--data-binary @ sample.json
在您的情况下,请求将如下所示: curl -H'内容类型:application / x-ndjson'-XPOST'localhost:9200 / schools / _bulk?pretty'--data-binary @ schools-sample.json
schools-sample.json内容:
{"index":{"_index":"schools", "_type":"school", "_id":"1"}}
{"name":"Central School", "description":"CBSE Affiliation", "street":"Nagan","city":"paprola", "state":"HP", "zip":"176115", "location":[31.8955385, 76.8380405],"fees":2000, "tags":["Senior Secondary", "beautiful campus"], "rating":"3.5"}
{"index":{"_index":"schools", "_type":"school", "_id":"2"}}
{"name":"Saint Paul School", "description":"ICSE Afiliation", "street":"Dawarka", "city":"Delhi", "state":"Delhi", "zip":"110075","location":[28.5733056, 77.0122136], "fees":5000,"tags":["Good Faculty", "Great Sports"], "rating":"4.5"}
/n
重要:数据的最后一行必须以换行符\ n结尾。每个换行符前面都可以有一个回车符\ r。否则,您将得到一个错误:
{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "The bulk request must be terminated by a newline [\n]"
}
],
"type" : "illegal_argument_exception",
"reason" : "The bulk request must be terminated by a newline [\n]"
},
"status" : 400
}