ElasticSearch索引
简介
索引是具有相同结构的文档集合。在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索引的更多相关文章
- Elasticsearch索引(company)_Centos下CURL增删改
目录 返回目录:http://www.cnblogs.com/hanyinglong/p/5464604.html 1.Elasticsearch索引说明 a. 通过上面几篇博客已经将Elastics ...
- ES3:ElasticSearch 索引
ElasticSearch是文档型数据库,索引(Index)定义了文档的逻辑存储和字段类型,每个索引可以包含多个文档类型,文档类型是文档的集合,文档以索引定义的逻辑存储模型,比如,指定分片和副本的数量 ...
- Elasticsearch索引和文档操作
列出所有索引 现在来看看我们的索引 GET /_cat/indices?v 响应 health status index uuid pri rep docs.count docs.deleted st ...
- Elasticsearch索引原理
转载 http://blog.csdn.net/endlu/article/details/51720299 最近在参与一个基于Elasticsearch作为底层数据框架提供大数据量(亿级)的实时统计 ...
- ElasticSearch 索引 剖析
ElasticSearch index 剖析 在看ElasticSearch权威指南基础入门中关于:分片内部原理这一小节内容后,大致对ElasticSearch的索引.搜索底层实现有了一个初步的认识. ...
- Elasticsearch 索引、更新、删除文档
一.Elasticsearch 索引(新建)一个文档的命令: curl XPUT ' http://localhost:9200/test_es_order_index/test_es_order_t ...
- Elasticsearch 索引的全量/增量更新
Elasticsearch 索引的全量/增量更新 当你的es 索引数据从mysql 全量导入之后,如何根据其他客户端改变索引数据源带来的变动来更新 es 索引数据呢. 首先用 Python 全量生成 ...
- ElasticSearch 索引模块——全文检索
curl -XPOST http://master:9200/djt/user/3/_update -d '{"doc":{"name":"我们是中国 ...
- Elasticsearch索引按月划分以及获取所有索引数据
项目中数据库根据月份水平划分,由于没有用数据库中间件,没办法一下查询所有订单信息,所有用Elasticsearch做订单检索. Elasticsearch索引和数据库分片同步,也是根据月份来建立索引. ...
- Elasticsearch入门教程(三):Elasticsearch索引&映射
原文:Elasticsearch入门教程(三):Elasticsearch索引&映射 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文 ...
随机推荐
- day 32 管道 事件 信号量 进程池
一.管道(多个时数据不安全) Pipe 类 (像队列一样,数据只能取走一次) conn1,conn2 = Pipe() 建立管道 .send() 发送 .recv() 接收 二.事 ...
- TypeScript 之 声明文件的使用
https://www.tslang.cn/docs/handbook/declaration-files/consumption.html 下载 在TypeScript 2.0以上的版本,获取类型声 ...
- PL/SQL Developer显示中文乱码
PL/SQL Developer显示中文乱码,可能是oracle客户端和服务器端的编码方式不一样. 解决方法: Select userenv('language') from dual; 设置环境变量 ...
- 简单脱壳教程笔记(2)---手脱UPX壳(1)
本笔记是针对ximo早期发的脱壳基础视频教程,整理的笔记. ximo早期发的脱壳基础视频教程 下载地址如下: http://down.52pojie.cn/%E5%90%BE%E7%88%B1%E7% ...
- MHA 报错:There is no alive slave. We can't do failover
dba http://blog.csdn.net/zengxuewen2045/article/details/51524880 关于这个错误: 1 2 3 4 Mon Feb 13 10:29: ...
- Delphi中使用ADO连接Excel
第一部分: . 设置ADOConnection的ConnectionString属性的OLE DB的提供者要选择Microsoft Jet 4.0 OLE DB Provider(这本来是用于连接Ac ...
- javascript map forEach filter some every在购物车中的实战演练区分用法
1.map forEach 1.map 循环遍历每一项,返回一个新的数组 例: 购物车商品小计: //购物车 var cart=[ {"id":101,"name&quo ...
- Python开发工具Atom
python基础教程之Python开发工具Atom 本节内容如下: Atom简介 下载安装Atom 安装Python开发包 使用Atom开发Python程序 Atom简介 Atom是Github开 ...
- linux 系统下有sda和hda的硬件设备分别代表什么意思
linux 系统下有sda和hda的硬件设备分别代表什么意思/dev/sda1 # SCSI设备,sda,sdb,sdc,三块盘,1,2,3代表分区(PV)/dev/sda2/dev/sdb1/dev ...
- 自动化测试Java一:Selenium入门
From: https://blog.csdn.net/u013258415/article/details/77750214 Selenium入门 欢迎阅读Selenium入门讲义,本讲义将会重点介 ...