我是elastisearch的新手,所以很抱歉这是一个新手问题。
基本上,我正在尝试将PUT
的一些数据放入创建的索引中。
我正在使用此代码(在命令提示符下):
curl -XPUT -x "" "http://127.0.0.1:9200/test/' -d '{"user" : "kimchy", "post_date" : "2009-11-15T14:12:12","message" : "trying"}
但是在命令提示符下,出现此错误:
[1/3]: http://127.0.0.1:9200/test/' -d 'user : kimchy --> <stdout>
--_curl_--http://127.0.0.1:9200/test/' -d 'user : kimchy
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"invalid v
ersion format: -D 'USER : KIMCHY HTTP/1.1"}],"type":"illegal_argument_exception
","reason":"invalid version format: -D 'USER : KIMCHY HTTP/1.1"},"status":400}
[2/3]: http://127.0.0.1:9200/test/' -d ' post_date : 2009-11-15T14:12:12 --> <s
tdout>
--_curl_--http://127.0.0.1:9200/test/' -d ' post_date : 2009-11-15T14:12:12
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"invalid v
ersion format: -D ' POST_DATE : 2009-11-15T14:12:12 HTTP/1.1"}],"type":"illegal
_argument_exception","reason":"invalid version format: -D ' POST_DATE : 2009-11-
15T14:12:12 HTTP/1.1"},"status":400}
[3/3]: http://127.0.0.1:9200/test/' -d 'message : trying --> <stdout>
--_curl_--http://127.0.0.1:9200/test/' -d 'message : trying
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"invalid v
ersion format: -D 'MESSAGE : TRYING HTTP/1.1"}],"type":"illegal_argument_except
ion","reason":"invalid version format: -D 'MESSAGE : TRYING HTTP/1.1"},"status"
:400}
请帮助。我知道它是如此简单,但是我找不到它。
谢谢。
编辑:
当我尝试:
curl -H 'Content-Type: application/json' -XPUT 'http://127.0.0.1:9200/test/doc/1' -d '{"user" : "kimchy", "post_date" : "2009-11-15T14:12:12","message" : "trying"}'
我得到了(在命令提示符下):
*/
/* Page basics */
* {
font-family: verdana, sans-serif;
}
html body {
margin: 0;
padding: 0;
background: #efefef;
font-size: 12px;
color: #1e1e1e;
}
/* Page displayed title area */
#titles {
margin-left: 15px;
padding: 10px;
padding-left: 100px;
background: url('http://www.squid-cache.org/Artwork/SN.png') no-repeat l
eft;
}
/* initial title */
#titles h1 {
color: #000000;
}
#titles h2 {
color: #000000;
}
/* special event: FTP success page titles */
#titles ftpsuccess {
background-color:#00ff00;
width:100%;
}
/* Page displayed body content area */
#content {
padding: 10px;
background: #ffffff;
}
/* General text */
p {
}
/* error brief description */
#error p {
}
/* some data which may have caused the problem */
#data {
}
/* the error message received from the system or other software */
#sysmsg {
}
pre {
font-family:sans-serif;
}
/* special event: FTP / Gopher directory listing */
#dirmsg {
font-family: courier;
color: black;
font-size: 10pt;
}
#dirlisting {
margin-left: 2%;
margin-right: 2%;
}
#dirlisting tr.entry td.icon,td.filename,td.size,td.date {
border-bottom: groove;
}
#dirlisting td.size {
width: 50px;
text-align: right;
padding-right: 5px;
}
/* horizontal lines */
hr {
margin: 0;
}
/* page displayed footer area */
#footer {
font-size: 9px;
padding-left: 10px;
}
body
:lang(fa) { direction: rtl; font-size: 100%; font-family: Tahoma, Roya, sans-ser
if; float: right; }
:lang(he) { direction: rtl; float: right; }
--></style>
</head><body>
<div id="titles">
<h1>ERROR</h1>
<h2>The requested URL could not be retrieved</h2>
</div>
<hr>
<div id="content">
<p>The following error was encountered while trying to retrieve the URL: <a href
="http:///">http:///</a></p>
<blockquote id="error">
<p><b>Unable to determine IP address from host name <q></q></b></p>
</blockquote>
<p>The DNS server returned:</p>
<blockquote id="data">
<pre>Invalid hostname</pre>
</blockquote>
<p>This means that the cache was not able to resolve the hostname presented in t
he URL. Check if the address is correct.</p>
<p>Your cache administrator is <a href="mailto:webmaster?subject=CacheErrorInfo%
20-%20ERR_DNS_FAIL&body=CacheHost%3A%20asoju.unilag.edu.ng%0D%0AErrPage%3A%2
0ERR_DNS_FAIL%0D%0AErr%3A%20%5Bnone%5D%0D%0ADNS%20ErrMsg%3A%20Invalid%20hostname
%0D%0ATimeStamp%3A%20Fri,%2001%20Mar%202019%2015%3A50%3A22%20GMT%0D%0A%0D%0AClie
ntIP%3A%20196.45.55.33%0D%0A%0D%0AHTTP%20Request%3A%0D%0APUT%20%2F%20HTTP%2F1.0%
0AHost%3A%20%0D%0AUser-Agent%3A%20curl%2F7.64.0%0D%0AAccept%3A%20*%2F*%0D%0AProx
y-Connection%3A%20Keep-Alive%0D%0AContent-Length%3A%206%0D%0AContent-Type%3A%20a
pplication%2Fx-www-form-urlencoded%0D%0A%0D%0A%0D%0A">webmaster</a>.</p>
<br>
</div>
<hr>
<div id="footer">
<p>Generated Fri, 01 Mar 2019 15:50:22 GMT by asoju.unilag.edu.ng (squid/3.1.6)<
/p>
<!-- ERR_DNS_FAIL -->
</div>
</body></html>
curl: (3) URL using bad/illegal format or missing URL
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/st
rict.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ERROR: The requested URL could not be retrieved</title>
<style type="text/css"><!--
/*
Stylesheet for Squid Error pages
Adapted from design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License
*/
/* Page basics */
* {
font-family: verdana, sans-serif;
}
html body {
margin: 0;
padding: 0;
background: #efefef;
font-size: 12px;
color: #1e1e1e;
}
/* Page displayed title area */
#titles {
margin-left: 15px;
padding: 10px;
padding-left: 100px;
background: url('http://www.squid-cache.org/Artwork/SN.png') no-repeat l
eft;
}
/* initial title */
#titles h1 {
color: #000000;
}
#titles h2 {
color: #000000;
}
/* special event: FTP success page titles */
#titles ftpsuccess {
background-color:#00ff00;
width:100%;
}
/* Page displayed body content area */
#content {
padding: 10px;
background: #ffffff;
}
/* General text */
p {
}
/* error brief description */
#error p {
}
/* some data which may have caused the problem */
#data {
}
/* the error message received from the system or other software */
#sysmsg {
}
pre {
font-family:sans-serif;
}
/* special event: FTP / Gopher directory listing */
#dirmsg {
font-family: courier;
color: black;
font-size: 10pt;
}
#dirlisting {
margin-left: 2%;
margin-right: 2%;
}
#dirlisting tr.entry td.icon,td.filename,td.size,td.date {
border-bottom: groove;
}
#dirlisting td.size {
width: 50px;
text-align: right;
padding-right: 5px;
}
/* horizontal lines */
hr {
margin: 0;
}
/* page displayed footer area */
#footer {
font-size: 9px;
padding-left: 10px;
}
body
:lang(fa) { direction: rtl; font-size: 100%; font-family: Tahoma, Roya, sans-ser
if; float: right; }
:lang(he) { direction: rtl; float: right; }
--></style>
</head><body>
<div id="titles">
<h1>ERROR</h1>
<h2>The requested URL could not be retrieved</h2>
</div>
<hr>
<div id="content">
<p>The following error was encountered while trying to retrieve the URL: <a href
="http:///">http:///</a></p>
<blockquote id="error">
<p><b>Unable to determine IP address from host name <q></q></b></p>
</blockquote>
<p>The DNS server returned:</p>
<blockquote id="data">
<pre>Invalid hostname</pre>
</blockquote>
<p>This means that the cache was not able to resolve the hostname presented in t
he URL. Check if the address is correct.</p>
<p>Your cache administrator is <a href="mailto:webmaster?subject=CacheErrorInfo%
20-%20ERR_DNS_FAIL&body=CacheHost%3A%20asoju.unilag.edu.ng%0D%0AErrPage%3A%2
0ERR_DNS_FAIL%0D%0AErr%3A%20%5Bnone%5D%0D%0ADNS%20ErrMsg%3A%20Invalid%20hostname
%0D%0ATimeStamp%3A%20Fri,%2001%20Mar%202019%2015%3A50%3A22%20GMT%0D%0A%0D%0AClie
ntIP%3A%20196.45.55.33%0D%0A%0D%0AHTTP%20Request%3A%0D%0APUT%20%2F%20HTTP%2F1.0%
0AHost%3A%20%0D%0AUser-Agent%3A%20curl%2F7.64.0%0D%0AAccept%3A%20*%2F*%0D%0AProx
y-Connection%3A%20Keep-Alive%0D%0AContent-Length%3A%206%0D%0AContent-Type%3A%20a
pplication%2Fx-www-form-urlencoded%0D%0A%0D%0A%0D%0A">webmaster</a>.</p>
<br>
</div>
<hr>
<div id="footer">
<p>Generated Fri, 01 Mar 2019 15:50:22 GMT by asoju.unilag.edu.ng (squid/3.1.6)<
/p>
<!-- ERR_DNS_FAIL -->
</div>
</body></html>
curl: (3) unmatched close brace/bracket in URL position 7:
trying}'
^
答案 0 :(得分:0)
问题是您混合使用双引号和单引号
"http://127.0.0.1:9200/test/'
^ ^
尝试一下:
curl -H 'Content-Type: application/json' -XPUT 'http://127.0.0.1:9200/test/doc/1' -d '{"user" : "kimchy", "post_date" : "2009-11-15T14:12:12","message" : "trying"}'
在Windows上:
curl -H "Content-Type: application/json" -XPUT "http://127.0.0.1:9200/test/doc/1" -d "{\"user\" : \"kimchy\", \"post_date\" : \"2009-11-15T14:12:12\",\"message\" : \"trying\"}"