简介

索引是具有相同结构的文档集合。在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. 利用 MessageRPC 和 ShareMemory 来实现 分布式并行计算

    可以利用 MessageRPC + ShareMemory 来实现 分布式并行计算 . MessageRPC :  https://www.cnblogs.com/KSongKing/p/945541 ...

  2. buntu下备份系统的方法

    今天不小心强行结束了一不知道用处的进程,结果造成进不了x界面,gdm启动不了,使用apt-get进行修复,结果几乎要把整个x界面有关的软件包删除,所以只好重装系统,为了防止下次出现类似的问题,所以把系 ...

  3. [转]DB2错误代码大全

    DB2 SQLSTATE 消息 异常 一2008-03-31 13:17SQLSTATE 消息本节列示 SQLSTATE 及其含义.SQLSTATE 是按类代码进行分组的:对于子代码,请参阅相应的表. ...

  4. mysql之 CentOS系统针对mysql参数优化

    内核相关参数(/etc/sysctl.conf)  以下参数可以直接放到sysctl.conf文件的末尾: net.core.somaxconn = 65535 net.core.netdev_max ...

  5. MySQL中如何实现 select top n

    mysql 没有 top n 语法,mysql 用 limit 来实现相关功能,而且功能更加强大. 语法: SELECT * FROM table LIMIT [offset,] rows | row ...

  6. 如果指针为空,返回ERROR

    if(!p) //是!p而不是p return ERROR;

  7. mysql5.5 for linux 安装(转)

    下载地址: http://dev.mysql.com/downloads/mysql/5.5.html#downloads 进入后会有选择系统 选择linux-generic后 又有很多产品选择,我们 ...

  8. Typescript学习总结之泛型

    泛型: 参数化的类型,一般用来限制结合的内容 class Student { constructor(public name: string) { } say() { console.log(this ...

  9. php输出异常的检查方法

    同事在用php展示验证码时,老是无法正常显示 但是的代码在别的地方正常运行 查看了输出,是有内容的,但是就是不显示 根据经验,应该是输出的内容有混淆,就是说在输出图片内容的时候,掺杂进去额外的信息 通 ...

  10. linux在线中文手册

    linux在线中文手册 http://linux.51yip.com/ 百度中的百度应用也不错 http://www.baidu.com/s?word=linux%E5%91%BD%E4%BB%A4& ...