elasticsearch入门学习

来源:互联网 发布:iea数据公布 编辑:程序博客网 时间:2024/05/24 06:30

一,索引添加

curl -X PUT 'http://localhost:9200//website/blog/123' -d'
{
  "title": "My first blog entry",
  "text":  "Just trying this out...",
  "date":  "2014/01/01"
}'


二 查询

  curl -X GET http://localhost:9200//website/blog/124?pretty  

//pretty参数对查询结果输出进行优化

 

{  "_index" : "website",  "_type" : "blog",  "_id" : "123",  "_version" : 1,  "found" : true,  "_source":{  "title": "My first blog entry",  "text":  "Just trying this out...",  "date":  "2014/01/01"}}


curl -X GET http://localhost:9200//website/blog/124?pretty_source=title,text  //对_source字段进行过来

{  "_index": "website",  "_type": "blog",  "_id": "123",  "_version": 1,  "found": true,  "_source": {    "title": "My first blog entry",    "text": "Just trying this out...",    "date": "2014/01/01"  }}

三 查看文档是否存在,而不关心文件内容 (curl -i -XHEAD http://localhost:9200/website/blog/123) -i   -XHEAD

    HTTP/1.1 200 OK

curl -i -XHEAD http://localhost:9200/website/blog/124

   HTTP/1.1 404 Not Found

四 简单文档更新(下面只能下date字段)

  curl -X PUT 'http://localhost:9200//website/blog/123' -d'
  {
     "title": "My first blog entry",
     "text":  "Just trying this out...",
     "date":  "2014/01/02"
}'

查询数据(发现_verssion字段变成2在内部,Elasticsearch已经标记旧文档为删除并添加了一个完整的新文档。旧版本文档不会立即消失,但你也不能去访问它。Elasticsearch会在你继续索引更多数据时清理被删除的文档。

{  "_index": "website",  "_type": "blog",  "_id": "123",  "_version": 2,  "found": true,  "_source": {    "title": "My first blog entry",    "text": "Just trying this out...",    "date": "2014/01/02"  }}

五 文档删除(curl -XDELETE 'http://localhost:9200//website/blog/123')

{"found":true,"_index":"website","_type":"blog","_id":"123","_version":3}

 

六,修改外部版本号

 

PUT /website/blog/2?version=10&version_type=external{  "title": "My first external blog entry",  "text":  "This is a piece of cake..."}请求成功的设置了当前_version为10:{  "_index":   "website",  "_type":    "blog",  "_id":      "2",  "_version": 10,  "created":  false}

七 update文档

 

最简单的update请求表单接受一个局部文档参数doc,它会合并到现有文档中——对象合并在一起,存在的标量字段被覆盖,新字段被添加。举个例子,我们可以使用以下请求为博客添加一个tags字段和一个views字段:POST /website/blog/1/_update{   "doc" : {      "tags" : [ "testing" ],      "views": 0   }}


 

0 0
原创粉丝点击