一、索引初始化操作

插件推荐使用head、marvel (收费)

1.1 创建新索引

curl -XPUT 'http://localhost:9200/test' -d '
{
"settings":{
"index":{
"number_of_shards": 5,
"number_of_replicas": 1
}
}
}
'

返回如下内容即为成功:

{
"acknowledged": true,
"shards_acknowledged": true,
"index": "test"
}

number_of_replicas可以替换为:

blocks.read_only : 设为true, 则当前索引只允许读,不允许写或更新;

blocks.read : 设为true , 则禁止读操作;

blocks.write : 设为true , 则禁止写操作;

blocks.metadata : 设为true , 则禁止对metadata操作。

1.2 查询索引的设置信息

curl -XGET 'http://localhost:9200/test/_settings?pretty'
curl -XGET 'http://localhost:9200/test,test2/_settings?pretty'
curl -XGET 'http://localhost:9200/_all/_settings?pretty'

1.3  创建文档

curl -XPUT 'http://localhost:9200/test/book/1' -d '
{
"title": "ZQW Book",
"name": {
"first": "Z",
"last": "QW"
},
"publish_date": "2017-11-20",
"price": "39.99"
}
'

不设置文档ID

curl -XPOST 'http://localhost:9200/test/book/' -d '
{
"title": "No ID",
"name": {
"first": "Z",
"last": "QW"
},
"publish_date": "2017-11-20",
"price": "39.99"
}
'

1.4 获取文档

curl -XGET 'http://localhost:9200/test/book/1'

1.5 通过 _source 获取指定字段

curl -XGET localhost:9200/test/book/1?_source=title
curl -XGET localhost:9200/test/book/1?_source=title,price
curl -XGET localhost:9200/test/book/1?_source

1.6 更新文档

curl -XPOST 'http://localhost:9200/test/book/1/_update' -d '
{
"doc" : {
"price" : "free"
}
}
'

1.7 删除文档

curl -XDELETE 'http://localhost:9200/test/book/1'
curl -XDELETE 'http://localhost:9200/test/book'
curl -XDELETE 'http://localhost:9200/test'

1.8 _mget 批量获取

curl -XPOST 'http://localhost:9200/_mget' -d '
#### docs 属组 ####
{
"docs": [
{
"_index": "library",
"_type": "book",
"_id": 2
},
{
"_index": "library",
"_type": "book",
"_id": 3,
#####只获取指定数据#####
    "_source" : "price"
},
{
"_index": "shop",
"_type": "apple",
"_id": 1
}
]
}
'

相同index,type下通过不同ID批量寻找文档

curl -XPOST 'http://localhost:9200/library/book/_mget' -d '
{
"docs" : [
{ "_id" : 1 },
{ "_type" : "book", "_id" : 2 }
]
}
#####或者如下#####
{
"ids": [ 0, 1, 2, 3, 4 ]
}
'

1.9 bulk 批量操作

实现多个文档的 create、index、update 或 delete 操作

请求体格式(不能如同常规JSON格式一般美化展示):

{action:{metadata}}\n

{request body}\n

ex: { "delete" : { "_index" : "test","_type" : "type","_id" : "1" } }

curl -XPOST 'http://localhost:9200/test/type/_bulk' -d '
{ "index": {"_id": 0}}
{ "title" : "test00","exist": "true"}
{ "index": {"_id": 1}}
{ "title" : "test01","exist": "true"}
{ "index": {"_id": 2}}
{ "title" : "test02","exist": "true"}
{ "index": {"_id": 3}}
{ "title" : "test03","exist": "true"}
{ "index": {"_id": 4}}
{ "title" : "test04","exist": "true"}
'

批量操作:

curl -XPOST 'http://localhost:9200/test/type/_bulk?pretty' -d '
{"delete": {"_index": "test","_type": "type","_id" : ""}}
{"create": {"_index": "meta","_type":"mtype","_id":""}}
{"title":"meta_type01","exist":"true"}
{"index":{"_index": "meta","_type":"mtype"}}
{"title":"meta_type02","exist":"true"}
{"update":{"_index":"test","_type":"type","_id":""}}
{"doc":{"exist":"false"}}
'

bulk处理文档大小的最佳值:

  • 数据加载在每个节点的RAM里
  • 请求的数据超过一定的大小,那bulk的 处理性能就回降低
  • 文档数据大小跟数据配置,文档复杂度,以及当前集群的负载有关

2.0 版本控制

  • 悲观锁:假定会发生并发冲突,屏蔽一切可能违反数据完整性的操作。(安全)
  • 乐观锁:假定不会发生并发冲突,只在提交操作时检查是否违反数据的完整性。

Elasticsearch 内置使用的是乐观锁:

  • 内部版本控制:每次修改后,_version自增长
  • 外部版本控制:手动修改_version
curl -XPUT 'http://localhost:9200/test/type/3?version=5&version_type=external' -d '
{
"title":""
}
'

Elasticsearch索引操作的更多相关文章

  1. Elasticsearch 索引操作

    一.创建 语法: PUT /索引库名称 { "settings": { "number_of_shards": 分片数量, "number_of_re ...

  2. ElasticSearch Index操作源码分析

    ElasticSearch Index操作源码分析 本文记录ElasticSearch创建索引执行源码流程.从执行流程角度看一下创建索引会涉及到哪些服务(比如AllocationService.Mas ...

  3. ElasticSearch+Kibana 索引操作( 附源码)

    一 前言 ElasticiSearch 简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Elastics ...

  4. ElasticSearch+Kibana 索引操作

    ElasticSearch+Kibana 索引操作 一 前言 ElasticiSearch 简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引 ...

  5. Elasticsearch索引和文档操作

    列出所有索引 现在来看看我们的索引 GET /_cat/indices?v 响应 health status index uuid pri rep docs.count docs.deleted st ...

  6. elasticsearch的索引操作和文档操作总结

    参考文档:https://es.xiaoleilu.com/010_Intro/00_README.html 一.索引操作 1.查看当前节点的所有的index 查看当前节点的所有的index [roo ...

  7. ElasticSearch 基本概念 and 索引操作 and 文档操作 and 批量操作 and 结构化查询 and 过滤查询

    基本概念 索引: 类似于MySQL的表.索引的结构为全文搜索作准备,不存储原始的数据. 索引可以做分布式.每一个索引有一个或者多个分片 shard.每一个分片可以有多个副本 replica. 文档: ...

  8. Elasticsearch索引(company)_Centos下CURL增删改

    目录 返回目录:http://www.cnblogs.com/hanyinglong/p/5464604.html 1.Elasticsearch索引说明 a. 通过上面几篇博客已经将Elastics ...

  9. Elasticsearch-PHP 索引操作(转)

    索引操作 本节通过客户端来介绍一下索引API的各种操作.索引操作包含任何管理索引本身(例如,创建索引,删除索引,更改映射等等). 我们通过一些常见的操作的代码片段来介绍,然后在表格中列出剩下的方法.R ...

随机推荐

  1. 接口测试 dubbo 接口测试

    dubbo是阿里巴巴开源的一套rpc方案,以为理念很契合微服务,这几年很火,用户里面不凡京东,当当,去哪儿等大公司.rpc场景   dubbo架构   官网也提供了一个很简单实用的demo来演示dub ...

  2. IntelliJ IDEA入门之常用配置以及问题解决(持续更新中)

    软件版本: IntelliJ IDEA 2019.1.1(Ultimate Edition) 运行环境: JDK1.8, Tomcat8.0, Maven3.6 我们在学习新的无论是jar包, 框架, ...

  3. PJzhang:kali linux安装virtualbox虚拟机和chrome浏览器

    猫宁!!! 参考链接: https://www.cnblogs.com/zhishuai/p/8007410.html kali linux 安装virtualbox. 查询系统的版本 apt-cac ...

  4. 【AMAD】django-oauth-toolkit -- 为Django集成Oauth2加入一些好货!

    简介 个人评分 简介 如果你面对下面其中的一个问题: 你的Django app需要暴露一个接口,你希望能够收到Oauth2协议的保护 你需要实现Oauth2鉴权服务器,让你的基础设施可以进行token ...

  5. 【Web网站服务器开发】Apache 和 Tomcat的区别及配置

    Apache 和 Tomcat 都是web网络服务器,两者既有联系又有区别,在进行HTML.PHP.JSP.Perl等开发过程中,需要准确掌握其各自特点,选择最佳的服务器配置. apache是web服 ...

  6. Thinkphp+Ajax带关键词搜索列表无刷新分页实例

    Thinkphp+Ajax带关键词搜索列表无刷新分页实例,两个查询条件,分页和搜索关键字,懂的朋友还可以添加其他分页参数. 搜索#keyword和加载内容区域#ajax_lists <input ...

  7. CSS基础布局

    目录 css基础布局 1.布局相关的标签 2.盒子模型 2-1 什么是盒子模型 2-2 块级元素和内联元素(行内元素) 2-3 盒子模型之间的关系 盒子模型相关CSS属性 3.浮动 3-1 什么是浮动 ...

  8. 基于keepalived搭建mysql双主高可用

    目录 概述 环境准备 keepalived搭建 mysql搭建 mysql双主搭建 mysql双主高可用搭建 概述 传统(不借助中间件)的数据库主从搭建,如果主节点挂掉了,从节点只能读取无法写入,只能 ...

  9. 贝叶斯线性回归(Bayesian Linear Regression)

    贝叶斯线性回归(Bayesian Linear Regression) 2016年06月21日 09:50:40 Duanxx 阅读数 54254更多 分类专栏: 监督学习   版权声明:本文为博主原 ...

  10. SSM(Spring+SpringMVC+MyBatis)高并发优化思路

    SSM(Spring+SpringMVC+MyBatis)框架集由Spring.MyBatis两个开源框架整合而成(SpringMVC是Spring中的部分内容).常作为数据源较简单的web项目的框架 ...