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版权协议,转载请附上原文出处链接和本声明. 本文 ...
随机推荐
- Debug outlook add-in (office.js) 小技巧
这几天在使用office.js 做outlook add-in的时候出现了一个问题: 不知道运行时去调试. 这里给大家介绍两个调试add-in 的方法. office365 其他软件 add-ins ...
- Hi3516CV300 sample -> region
- vue线上项目,优化前后对比
优化前: dev初次时间:52s dev时间:5s~6s build时间:374s(6.2分钟) build后zip包大小: vue.vue-router 优化后: dev初次时间:49s.48s.5 ...
- Python画图代码
X1D=np.linspace(-4, 4, 9).reshape(-1,1) X2D=np.c_[X1D, X1D**2] y = np.array([0, 0, 1, 1, 1, 1, 1, 0, ...
- [VC6] 小谈如何解决VC6.0 open崩溃的问题(已解决)(转)
[昨天重装了系统,开始用VC6还是可以的,后来装了WPS,在用VC6里面的Open就崩溃了. 这个解决方法就这么几步:1.把FileTool.dll放到指定的AddIns目录.2. 注册这个dll到注 ...
- org.apache.ibatis.binding.BindingException: Invalid bound statement
idea中出现了这个问题 我的解决方案是: 把mapper映射文件放到资源目录下 然后就行了. 当然,这个具体原因就是:mapper.xml和接口对不上引起的,具体问题还要具体解决 协助博客:http ...
- Modbus RTU 协议使用汇总
原创地址:https://blog.csdn.net/u012166958/article/details/64920144 标准的Modbus 口是使用RS-232C 兼容串行接口,它定义了连接口的 ...
- js 复制文本到剪贴板
js 复制文本到剪贴板 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...
- 关于在项目中使用spring data redis与jedis的选择
项目中需要用到redis,主要用来作为缓存,redis的客户端有两种实现方式,一是可以直接调用jedis来实现,二是可以使用spring data redis,通过spring的封装来调用. 应该使用 ...
- 【AMQ】之JMS概念
1.JMS(Java Message Service)Java消息服务,是Java20几种技术其中之一 2.JMS规范定义了Java中访问消息中间件的接口,但是没有给实现,这个实现就是由第三方使用者来 ...