我在执行R包elastic(elastic_0.7.8)的某些功能时遇到了问题。具体来说,我尝试使用mapping_create
函数从JSON字符串创建映射。
无论我使用哪种JSON格式,我都会遇到同样的错误。例如,从documentation(第38页)执行一个示例:
library(elastic)
connect(es_host = "host_url", es_port = 9210, es_path = "/")
body <- '{
"citation": {
"properties": {
"journal": { "type": "string" },
"year": { "type": "long" }
}
}
}'
> mapping_create(index = "plos", type = "citation", body=body)
Error: lexical error: invalid char in json text.
No handler found for uri [///pl
(right here) ------^
其他包函数工作正常,例如,我可以执行mapping_get('_all')
并检索所有索引,或使用mapping_get(index = "createdIndex")
并检索已创建的索引。有没有人有类似的问题?
编辑。
Elasticsearch版本5.2.2 R版本3.3.2
> mapping_get(index = "plos", type = "citation", config=httr::verbose())
-> GET //plos/_mapping/citation HTTP/1.1
-> User-Agent: libcurl/7.29.0 r-curl/2.2 httr/1.2.1
-> Host: server-url:9200
-> Accept-Encoding: gzip, deflate
-> Accept: application/json, text/xml, application/xml, */*
->
<- HTTP/1.1 400 Bad Request
<- content-type: text/plain; charset=UTF-8
<- content-encoding: gzip
<- transfer-encoding: chunked
<-
Error: lexical error: invalid char in json text.
No handler found for uri [//tpm
(right here) ------^
任何帮助都将不胜感激。
编辑2:
从github elastic_0.7.8.9614
安装新版本后,会显示另一个错误:
> mapping_create(index = "plos", type = "citation", body=body)
Error: 404 - no such index
sessionInfo()
结果:
other attached packages:
[1] data.table_1.10.0 R.utils_2.5.0 R.oo_1.21.0 R.methodsS3_1.7.1 elastic_0.7.8.9614
loaded via a namespace (and not attached):
[1] httr_1.2.1 R6_2.2.0 tools_3.3.2 curl_2.6 jsonlite_1.5
编辑3
> config=httr::verbose()
> print(config)
<request>
Options:
* debugfunction: function (type, msg)
{
switch(type + 1, text = if (info) prefix_message("* ", msg), headerIn = prefix_message("<- ", msg), headerOut = prefix_message("-> ", msg), dataIn = if (data_in) prefix_message("<< ", msg, TRUE), dataOut = if (data_out) prefix_message(">> ", msg, TRUE), sslDataIn = if (data_in && ssl) prefix_message("*< ", msg, TRUE), sslDataOut = if (data_out && ssl) prefix_message("*> ", msg, TRUE))
}
* verbose: TRUE