简介

索引是具有相同结构的文档集合。在Elasticsearch中索引是个非常重要的内容,对Elasticsearch的大部分操作都是基于索引来完成的。同时索引可以类比关系型数据库Mysql中的数据库database

创建索引

创建索引的时候可以通过修改number of shards和 number of replicas参数的数量来修改分片和副本的数量。在默认的情况下分片的数量是5个,副本的数量是1个

例如创建三个主分片两个副本分片的索引

PUT /secisland
{
"settings": {
"index":{"number_of_shards":3,"number_of_replicas":2}
}
}
#参数可以简写为
{"settings": {"number_of_shards":3,"number_of_replicas":2}}

修改索引

PUT /test_index/_settings
{
"number_of_replicas":1
}

对于任何Elasticsearch文档而言,一个文档会包括一个或者多个字段,任何字段都要有自己的数据类型,例如string、integer、date等。Elasticsearch中是通过映射来进行字段和数据类型对应的。在默认的情况下Elasticsearch会自动识别字段的数据类型。同时Elasticsearch提供了 mappings参数可以显式地进行映射。

PUT /test_index1
{
"settings": {"number_of_shards":3,"number_of_replicas":2},
"mappings": {"secilog": {"properties": {"logType": {"type": "string",
"index": "not_analyzed"}}}}
}

删除索引

DELETE /test_index

获取索引

GET /test_index1
{
"test_index1": {
"aliases": {},
"mappings": {
"secilog": {
"properties": {
"logType": {
"type": "keyword"
}
}
}
},
"settings": {
"index": {
"creation_date": "1544886365769",
"number_of_shards": "3",
"number_of_replicas": "2",
"uuid": "Iz8evLbCQ1CS85owEbKsgQ",
"version": {
"created": "5020299"
},
"provided_name": "test_index1"
}
}
}
}

过滤查询

索引的settings和mappings属性。可配置的属性包括 settings、 mappingswarmers 和 aliases。
GET /test_index1/_settings,_mapping, 如果索引不存在则返回404
{
"test_index1": {
"settings": {
"index": {
"creation_date": "1544886365769",
"number_of_shards": "3",
"number_of_replicas": "2",
"uuid": "Iz8evLbCQ1CS85owEbKsgQ",
"version": {
"created": "5020299"
},
"provided_name": "test_index1"
}
},
"mappings": {
"secilog": {
"properties": {
"logType": {
"type": "keyword"
}
}
}
}
}
}

关闭索引

映射管理

增加映射

PUT /test_index2
{
"mappings": {
"log": {
"properties": {
"message": {
"type": "string"
}
}
}
}
#以上接口添加索引名为test_index2,文档类型为log,其中包含字段message,字段类型是字符串:
PUT test_index2/_mapping/user
{
"properties": {
"name":{"type": "string"}
}
}
# 添加文档类型为user,包含字段name,字段类型是字符串。
#设置多个索引映射时
PUT /{index}/_mapping/{type}
{index}可以有多种方式,逗号分隔:比如testl,test2,test3。
all表示所有索引3通配符*表示所有。test*表示以test开头。
{type}需要添加或更新的文档类型。
{body}需要添加的字段或字段类型

获取映射

系统同时支持获取多个索引和类型的语法。
获取文档映射接口一次可以获取多个索引或文档映射类型。该接口通常是如下格式:
host:port/{index}/ mapping/{type}, {index}和{type}可以接受逗号(,)分隔符,也可以使用
GET  test_index2/_mapping/{string}
GET /test_index2/_mapping/log,user

判断存在

健查索引或文档类型是否存在 存在返回200 不存在返回404

HEAD test_index2/secilog

索引别名

Elasticsearch可以对一个或多个索引指定别名,通过别名可以查询一个或多个索引内容,在内部Elasticsearch会把别名映射在索引上,别名不可以和索引名其他索引别名重复

POST /_aliases
{
"actions":{"add":{"index":"test_index1","aliases":"othername1"}}
}
#给test_index增加索引别名othername1

修改别名

别名没有修改的语法,当需要修改时,先删除 ,在添加

POST /_aliases
{
"actions":{"remove":{"index":"test_index1","aliases":"othername2"}}
}

删除别名

DELETE  http://{host}:{port}/{index}/_alias/{name}

查询别名

GET  http://{host}:{port}/{index}/_alias/{name}

ElasticSearch索引的更多相关文章

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

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

  2. ES3:ElasticSearch 索引

    ElasticSearch是文档型数据库,索引(Index)定义了文档的逻辑存储和字段类型,每个索引可以包含多个文档类型,文档类型是文档的集合,文档以索引定义的逻辑存储模型,比如,指定分片和副本的数量 ...

  3. Elasticsearch索引和文档操作

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

  4. Elasticsearch索引原理

    转载 http://blog.csdn.net/endlu/article/details/51720299 最近在参与一个基于Elasticsearch作为底层数据框架提供大数据量(亿级)的实时统计 ...

  5. ElasticSearch 索引 剖析

    ElasticSearch index 剖析 在看ElasticSearch权威指南基础入门中关于:分片内部原理这一小节内容后,大致对ElasticSearch的索引.搜索底层实现有了一个初步的认识. ...

  6. Elasticsearch 索引、更新、删除文档

    一.Elasticsearch 索引(新建)一个文档的命令: curl XPUT ' http://localhost:9200/test_es_order_index/test_es_order_t ...

  7. Elasticsearch 索引的全量/增量更新

    Elasticsearch 索引的全量/增量更新 当你的es 索引数据从mysql 全量导入之后,如何根据其他客户端改变索引数据源带来的变动来更新 es 索引数据呢. 首先用 Python 全量生成 ...

  8. ElasticSearch 索引模块——全文检索

    curl -XPOST http://master:9200/djt/user/3/_update -d '{"doc":{"name":"我们是中国 ...

  9. Elasticsearch索引按月划分以及获取所有索引数据

    项目中数据库根据月份水平划分,由于没有用数据库中间件,没办法一下查询所有订单信息,所有用Elasticsearch做订单检索. Elasticsearch索引和数据库分片同步,也是根据月份来建立索引. ...

  10. Elasticsearch入门教程(三):Elasticsearch索引&映射

    原文:Elasticsearch入门教程(三):Elasticsearch索引&映射 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文 ...

随机推荐

  1. 网易的Airtest

    使用心得:https://testerhome.com/topics/12391 下载路径:https://airtest.netease.com/

  2. 套接字选项——getsockopt和setsockopt

    这两个函数仅用于套接字 #include <sys/socket.h> int getsockopt(int sock, int level, int optname, void *opt ...

  3. 决策树原理实例(python代码实现)

    决策数(Decision Tree)在机器学习中也是比较常见的一种算法,属于监督学习中的一种.看字面意思应该也比较容易理解,相比其他算法比如支持向量机(SVM)或神经网络,似乎决策树感觉“亲切”许多. ...

  4. Linux(CentOS7.0)下 C访问MySQL (转)

    按语:      最近项目在云服务器上 centos6.8,安装了mysql5.5.39 server和client,但C连接不知所措: 后在官网下载了 devel.share .share-comp ...

  5. java-plupload上传大文件

    参考链接: https://blog.csdn.net/hjf_1291030386/article/details/74784172 https://www.cnblogs.com/tengyunh ...

  6. 【转】mysql给root开启远程访问权限,修改root密码

    好记性不如烂笔头,偶然用一直忘.... mysql给root开启远程访问权限,修改root密码   1.MySql-Server 出于安全方面考虑只允许本机(localhost, 127.0.0.1) ...

  7. googletest--测试控制

    有时候如果某个测试出现了异常,但是我们想继续其他的测试怎么办. 最简单的方法就是,在测试的名字前加上"DISABLED_",如下面的例子所示: // Test with fixtu ...

  8. Redis持久化实践及灾难恢复模拟 [转]

    参考资料:Redis Persistence http://redis.io/topics/persistenceGoogle Groups https://groups.google.com/for ...

  9. 【异常处理】Springboot对Controller层方法进行统一异常处理

    Controller层方法,进行统一异常处理 提供两种不同的方案,如下: 方案1:使用 @@ControllerAdvice (或@RestControllerAdvice), @ExceptionH ...

  10. pandas 读mysql数据库(整个表或者表的指定列)

    问题1:如何从数据库中读取整个表数据到DataFrame中? 首先,来看很容易想到的的办法 def read_table_by_name(self, table_name): "" ...