Elasticsearch:Curl不工作 [英] Elasticsearch : Curl does not work
问题描述
我有ES 2.2.0和我试图
curl -XPOSThttp:// localhost:9200 d @ jnk.json
但我得到
警告:无法从文件jnk.json读取数据,这使得空POST。
没有为uri [/]和方法[POST]找到处理程序
的档案jnk.json
PUT junktest
{
mappings:{
test:{properties:{
DocumentID:{
type:string
},
Tags:{
type:string,
index:not_analyzed
},
Summary:{
type:string index:未分析
},
status:{
type:string,
index
Location:{
type:string,
index:not_analyzed
},
Error:{
type:string,
index:not_analyzed
},
Author:{
type:string,
index:not_analyzed
},
Sector:{
type:string,
index:not_analyzed }
创建日期:{
type:date,
format:yyyy-MM-dd
}
}
}
}
}
POST / junktest / test /
{
DocumentID:555661,
Tags:[A,B,C,D],
Summary:Summary Text,
Status: b $ bLocation: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 ,
Location:HDFS,
Error:None,
Author:Abc Mnb,
Sector:Energy
Created Date:2013-05-23
}
所以我创建一个映射,然后发布单个文档。我做错了什么?
我得到了 -XPUT
的相同结果
编辑
感谢@Bahaaldine Azarmi!有没有逗号,我能够单独创建映射:)但我尝试批量命令
curl -XPOST http:// localhost:9200 / _bulk--data-binary @ post.json
每个api,它给我错误
{error:{root_cause:[{type: json_parse_exception,reason:Unexpected char
acter(':'(code 58)):期望一个有效的值(数字,字符串,数组,对象,'t
rue','false'或null)\\\
at [Source:[B @ 2f1a62ab; line:1,column:27]}],typ
e:json_parse_exception,reason:Unexpected character :'(code 58)):expect
ed一个有效的值(数字,字符串,数组,对象,'true','false'或'null')\\\
at
[ B @ 2f1a62ab; line:1,column:27]},status:500}
这里是我的post.json
{index:{_index:junktest,_type:test }
{
DocumentID:555661,
Tags:[A,B,C,D
Summary:Summary Text,
Status:Review,
Location:HDFS,
Error:None b $ bAuthor:Poi KLj,
Sector:Energy,
Created Date:2013-04-23
}
我的语法有什么问题吗? :
字符不正确?
修复
$ b
批量API中不允许换行符,因为它们被视为分隔符。因此,文件的正确格式是
{index:{_ index:junktest,_ type: test}}
{DocumentID:555661,Tags:[A,B,C,D],摘要:摘要文本 :Review,Location:HDFS,Error:None,Author:Poi KLj,Sector:Energy,Created Date:2013-04-23 }
输入文件必须以换行符结尾 >
这些查询语法需要在Sense中复制和粘贴( https://www.elastic.co/blog/found-sense-a-cool-json-aware- interface-to-elasticsearch )。使用Sense,您将能够顺序运行每个查询。
如果要使用curl,请将工作分成两个调用:
使用以下代码创建映射
curl -XPUThttp:// localhost:9200 / junktest-d @ mapping.json
顺便说一句,你的映射在这里缺少一个逗号
},
创建日期:{
然后进行第二次调用,使用批量API在单个查询中索引您的Json对象,例如:
https://www.elastic.co/guide /en/elasticsearch/reference/current/docs-bulk.html
I have ES 2.2.0 and i am trying
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
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
Edit
thanks a lot @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
{"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
{ "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. 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). With Sense, you will be able to run every query sequentially.
If you want to use curl, then split the work in two calls:
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:
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
这篇关于Elasticsearch:Curl不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!