elasticsearch入门学习
2017-03-20 22:47
453 查看
一,索引添加
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参数对查询结果输出进行优化
curl -X GET http://localhost:9200//website/blog/124?pretty_source=title,text //对_source字段进行过来
三 查看文档是否存在,而不关心文件内容 (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会在你继续索引更多数据时清理被删除的文档。
五 文档删除(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
}
}
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
}
}
相关文章推荐
- ElasticSearch学习13_ElasticSearch RESTful搜索引擎_Java Jest使用入门
- (转)开源分布式搜索平台ELK(Elasticsearch+Logstash+Kibana)入门学习资源索引
- .net Elasticsearch 学习入门笔记
- Elastic Search系统学习之一: 入门
- 开源分布式搜索平台ELK(Elasticsearch+Logstash+Kibana)入门学习资源索引
- 开源分布式搜索平台ELK(Elasticsearch+Logstash+Kibana)入门学习资源索引
- ElasticSearch入门学习-基础示例(1)
- elasticsearch入门学习备忘
- 开源分布式搜索平台ELK(Elasticsearch+Logstash+Kibana)入门学习资源索引
- .net Elasticsearch 学习入门笔记
- ElasticSearch入门之风花雪月(五)
- ElasticSearch入门笔记
- ELK (ElasticSearch + Logstash + Kibaba + Marvel)系统的搭建学习与简单使用
- Elastic-2.1.1学习笔记(一)基础入门
- Elasticsearch.The.Definitive.Guide学习笔记 -- 3. Data in, Data in
- Elastic Search操作入门
- ElasticSearch API for JAVA 学习笔记
- ElasticSearch入门之风花雪月(五)
- ElasticSearch基本学习