我有ES 2.2.0,我正在尝试
curl -XPOST "http://localhost:9200" -d @jnk.json
但我明白了
Warning: Couldn't read data from file "jnk.json", this makes an empty POST. No handler found for uri [/] and method [POST]
这是文件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" }
所以我要创建一个映射,然后发布一个文档。我究竟做错了什么?
我得到相同的结果 -XPUT
-XPUT
编辑
非常感谢@Bahaaldine Azarmi!有一个缺少的逗号,我能够分别创建映射:),但我尝试使用bulk命令作为
curl -XPOST "http://localhost:9200/_bulk" --data-binary @post.json
按照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}
这是我的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" }
我的语法有问题吗?哪个:角色不合适?
:
固定
批量api中不允许使用换行符,因为它们被视为定界符。所以文件的正确格式是
{"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"}
输入文件 必须以换行符结尾
好了,这些查询语法需要在Sense中复制和粘贴(https://www.elastic.co/blog/found-sense-a-cool-json- aware-interface-to-elasticsearch)。使用Sense,您将能够顺序运行每个查询。
如果要使用curl,请将工作分为两个调用:
使用以下内容创建映射
curl -XPUT "http://localhost:9200/junktest" -d @mapping.json
顺便说一句,您的映射在这里缺少逗号
}, "Created Date": {
然后进行第二次调用,该调用使用批量API在单个查询中为您的Json对象建立索引,例如:
https://www.elastic.co/guide/zh-CN/elasticsearch/reference/current/docs- bulk.html