问题
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
回答1:
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
来源:https://stackoverflow.com/questions/35181736/elasticsearch-curl-does-not-work