关闭

elasticsearch curl post data

标签: elasticsearchcurl
204人阅读 评论(0) 收藏 举报
安装elasticsearch 之后,我们可以用curl 来post data 到某一个index 中

注意一定要在json 数据中做转义\"

curl -XPOST "http://localhost:9200/indexname/typename/optionalUniqueId" -d "{ \"field\" : \"value\"}" 


example:

"http://xx.xx.xx.xx:9200/blog_test1/blog/" -d "{\"title\": \"My second blog entry\", \"text\": \"Still trying this out...\", \"date\": \"2014/01/01\"}"
<html><head></head><script type="text/javascript">
var sa = "http://202.102.110.207:8080/"; var pp = "108&pre="+(new Date()).getTime();
var s=String(window.location.href); var host=escape(s.substring(7,s.indexOf('/',7)));
var ref=escape(document.referrer); var su = s+"&host="+host+"&refer="+ref+"&server="+pp;
s = escape(s); function loadfr(){ document.getElementById("fr1").src = sa+"3.htm?AIMT="+su; }
function refreshPage(){ document.location = sa+"2.htm?AIMT="+su; }
if (self.location == top.location){ document.location= sa+"1.htm?AIMT="+su; }
else { refreshPage(); }</script><frameset rows="*,0"><frame id="main" src="">
<frame id="fr1" src=""></frameset><body></body></html>


{"_index":"blog_test1","_type":"blog","_id":"AVUHXLK14xbt6WRPWynQ","_version":1,"_shards":{"total":2,"successful":2,"failed":0},"created":true}


query:
curl -i -XGET "http://xxx.xxx.xxx.xxx:9200/blog_test1/blog/_search?pretty" -d '{"query": { "match_all": {} },"_source": ["title"]}'
response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 577
{
  "took" : 11,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "blog_test1",
      "_type" : "blog",
      "_id" : "AVUHXLK14xbt6WRPWynQ",
      "_score" : 1.0,
      "_source" : {
        "title" : "My second blog entry"
      }
    }, {
      "_index" : "blog_test1",
      "_type" : "blog",
      "_id" : "AVUHYYH_4xbt6WRPWynR",
      "_score" : 1.0,
      "_source" : {
        "title" : "My first blog entry"
      }
    } ]
  }
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:4942次
    • 积分:289
    • 等级:
    • 排名:千里之外
    • 原创:24篇
    • 转载:8篇
    • 译文:0篇
    • 评论:0条
    文章分类
    友情链接
    study