每次我在Elasticsearch中按照有关创建索引,映射和添加数据的说明进行操作时,都会出现错误。我正在使用邮递员。首先,我创建索引:
POST http://localhost:9200/schools
Run Code Online (Sandbox Code Playgroud)
(实际上,我必须使用put才能成功创建)
接下来,我创建映射并添加数据:
POST http://localhost:9200/schools/_bulk
Run Code Online (Sandbox Code Playgroud)
请求正文
{
"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"
}
Run Code Online (Sandbox Code Playgroud)
但是我收到的只是:
{
"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
}
Run Code Online (Sandbox Code Playgroud)
这是因为您的请求正文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"
}
Run Code Online (Sandbox Code Playgroud)
您可以使用格式化和验证JSON的工具来确保它是有效的JSON。以下是一些示例。
https://jsonformatter.curiousconcept.com/
| 归档时间: |
|
| 查看次数: |
3313 次 |
| 最近记录: |