[英]Elasticsearch : Curl does not work
I have ES 2.2.0 and i am trying 我有ES 2.2.0,我正在尝试
curl -XPOST "http://localhost:9200" -d @jnk.json
but i get 但我明白了
Warning: Couldn't read data from file "jnk.json", this makes an empty POST.
No handler found for uri [/] and method [POST]
here are the contents of the file jnk.json 这是jnk.json文件的内容
PUT junktest
{
"mappings": {
"test": {"properties": {
"DocumentID": {
"type": "string"
},
"Tags":{
"type" : "string",
"index" : "not_analyzed"
},
"Summary": {
"type": "string",
"index" : "not_analyzed"
},
"Status": {
"type": "string",
"index" : "not_analyzed"
},
"Location": {
"type": "string",
"index" : "not_analyzed"
},
"Error": {
"type": "string",
"index" : "not_analyzed"
},
"Author": {
"type": "string",
"index" : "not_analyzed"
},
"Sector": {
"type": "string",
"index" : "not_analyzed"
}
"Created Date": {
"type": "date",
"format": "yyyy-MM-dd"
}
}
}
}
}
POST /junktest/test/
{
"DocumentID":"555661",
"Tags":["A","B","C","D"],
"Summary":"Summary Text",
"Status":"Review",
"Location":"HDFS",
"Error":"None",
"Author":"Poi KLj",
"Sector":"Energy",
"Created Date":"2013-04-23"
}
POST /junktest/test/
{
"DocumentID":"555662",
"Tags":["B","C","D"],
"Summary":"Summary Text",
"Status":"Review",
"Location":"HDFS",
"Error":"None",
"Author":"Abc Mnb",
"Sector":"Energy",
"Created Date":"2013-05-23"
}
so i am creating a mapping and then posting a single document. 所以我正在创建一个映射,然后发布一个文档。 What am i doing wrong?
我究竟做错了什么?
I get the same result for -XPUT
我得到了与
-XPUT
相同的结果
Edit 编辑
thanks a lot @Bahaaldine Azarmi! 非常感谢@Bahaaldine Azarmi! there was the missing comma and i was able to create the mapping separately :) but i tried the bulk command as
有缺少的逗号,我能够分别创建映射:)但我尝试了批量命令
curl -XPOST "http://localhost:9200/_bulk" --data-binary @post.json
as per the api, and it gave me error 根据api,它给了我错误
{"error":{"root_cause":[{"type":"json_parse_exception","reason":"Unexpected char
acter (':' (code 58)): expected a valid value (number, String, array, object, 't
rue', 'false' or 'null')\n at [Source: [B@2f1a62ab; line: 1, column: 27]"}],"typ
e":"json_parse_exception","reason":"Unexpected character (':' (code 58)): expect
ed a valid value (number, String, array, object, 'true', 'false' or 'null')\n at
[Source: [B@2f1a62ab; line: 1, column: 27]"},"status":500}
here is my post.json 这是我的post.json
{ "index" : { "_index" : "junktest", "_type" : "test"} }
{
"DocumentID":"555661",
"Tags":["A","B","C","D"],
"Summary":"Summary Text",
"Status":"Review",
"Location":"HDFS",
"Error":"None",
"Author":"Poi KLj",
"Sector":"Energy",
"Created Date":"2013-04-23"
}
is there something wrong with my syntax? 我的语法有问题吗? which
:
character is out of place? 哪个
:
角色不合适?
Fixed 固定
Line breaks are not allowed in bulk api as these are treated as delimiters. 批量api中不允许换行符,因为这些换行符被视为分隔符。 So the correct format of file is
所以文件的格式正确
{"index":{"_index":"junktest","_type":"test"}}
{"DocumentID":"555661","Tags":["A","B","C","D"],"Summary":"Summary Text","Status":"Review","Location":"HDFS","Error":"None","Author":"Poi KLj","Sector":"Energy","Created Date":"2013-04-23"}
the input file must end with a line break 输入文件必须以换行符结束
Well these queries syntaxes need to be copied and pasted in Sense ( https://www.elastic.co/blog/found-sense-a-cool-json-aware-interface-to-elasticsearch ). 这些查询语法需要在Sense中复制和粘贴( https://www.elastic.co/blog/found-sense-a-cool-json-aware-interface-to-elasticsearch )。 With Sense, you will be able to run every query sequentially.
使用Sense,您将能够按顺序运行每个查询。
If you want to use curl, then split the work in two calls: 如果你想使用curl,那么在两个调用中拆分工作:
Use the following to create your mapping 使用以下命令创建映射
curl -XPUT "http://localhost:9200/junktest" -d @mapping.json
By the way, your mapping is missing a comma here 顺便说一句,你的映射在这里缺少一个逗号
},
"Created Date": {
Then make a second call that use the bulk API to index your Json objects in a single query, example here: 然后进行第二次调用,使用批量API在单个查询中索引您的Json对象,例如:
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.