创建模板(模板名和索引名一样都不能有大写)

PUT http://222.108.x.x:9200/_template/templateds

{
"template": "dsideal*",
"order": 0,
"settings": {
"number_of_shards": 5
},
"aliases": {
"dsideal-query": {}      #起个别名
},
"mappings": {
"doc": {
"properties": {
"person_name": {
"type": "keyword"
},
"gender_id": {
"type": "long"
},
"bureau_id": {
"type": "long"
}
}
}
}
}

写一些数据

POST http://222.108.x.x:9200/dsideal10/doc/1

{
"person_name": "张三",
"gender_id": 1,
"bureau_id": 2
}

POST http://222.108.x.x:9200/dsideal11/doc/2

{
"person_name": "李四",
"gender_id": 2,
"bureau_id": 2
}

会按照模板自动生成两个索引“dsideal10”和“dsideal11”

可以利用在创建模板时起的别名进行查询

POST http://222.108.x.x:9200/dsideal-query/_search

{
"size": 10,
"query": {
"bool": {
"must": [
{
"term": {
"bureau_id": "2"
}
}
]
}
}
}

创建多个索引别名【备忘】

POST http://222.108.x.x:9200/_aliases

{
"actions" : [
{ "add" : { "index" : "dsideal1","alias" : "alias1" } },
{ "add" : { "index" : "dsideal2","alias" : "alias1" } }
]
}

在创建一个索引时可为这个索引根据条件创建多个别名

POST http://222.108.x.x:9200/test100

{
"aliases" : {
"2014" : {
"filter" : {
"term" : {"year": 2014 }
}
},
"2015" : {
"filter" : {
"term" : {"year": 2015 }
}
},
"2016" : {
"filter" : {
"term" : {"year": 2016 }
}
}
},
"mappings": {
"doc": {
"properties": {
"person_name": {
"type": "keyword"
},
"year": {
"type": "long"
},
"bureau_id": {
"type": "long"
}
}
}
}
}

说明:当插入year=2015的数据时可用2015这个别名去查询

测试插入一些数据

{"person_name":"张三","year":2014,"bureau_id":2},
{"person_name":"李四","year":2015,"bureau_id":3},
{"person_name":"王五","year":2015,"bureau_id":3},
{"person_name":"赵六","year":2016,"bureau_id":4}

post http://222.108.x.x:9200/2015/_search

{
"size": 10,
"query": {
"bool": {
"must": [
{
"match_all": { }
}
]
}
}
}

就只返回year=2015的数据

Elasticsearch索引模板和别名的更多相关文章

  1. Elasticsearch索引模板-转载

    转载地址:https://dongbo0737.github.io/2017/06/13/elasticsearch-template/#similar_posts Elasticsearch索引模板 ...

  2. ElasticStack学习(八):ElasticSearch索引模板与聚合分析初探

    一.Index Template与Dynamic Template的概念 1.Index Template:它是用来根据提前设定的Mappings和Settings,并按照一定的规则,自动匹配到新创建 ...

  3. ES 10 - Elasticsearch的索引别名和索引模板

    目录 1 索引模板概述 1.1 什么是索引模板 1.2 索引模板中的内容 1.3 索引模板的用途 2 创建索引模板 3 查看索引模板 4 删除索引模板 5 模板的使用建议 5.1 一个index中不能 ...

  4. Elasticsearch之索引模板index template与索引别名index alias

    为什么需要索引模板? 在实际工作中针对一批大量数据存储的时候需要使用多个索引库,如果手工指定每个索引库的配置信息(settings和mappings)的话就很麻烦了. 所以,这个时候,就存在创建索引模 ...

  5. elasticsearch 5.x 系列之四(索引模板的使用,详细得不要不要的)

    1,首先看一下下面这个索引模板 curl -XPUT "master:9200/_template/template_1?pretty" -H 'Content-Type: app ...

  6. ElasticSearch(六):索引模板

    ElasticSearch(六):索引模板 学习课程链接<Elasticsearch核心技术与实战> Index Template Index Template - 帮助你设定Mappin ...

  7. Elasticsearch学习笔记——索引模板

    在索引模板里面,date类型的字段的format支持多种类型,在es中全部会转换成long类型进行存储,参考 https://zhuanlan.zhihu.com/p/34240906 一个索引模板范 ...

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

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

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

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

随机推荐

  1. k64 datasheet学习笔记12---System Integration Module (SIM)

    1.前言 Features of the SIM include: System clocking configuration(1)System clock divide values(2) Arch ...

  2. Python os.removedirs() 和shutil.rmtree() 用于删除文件夹

    概述 os.removedirs() 方法用于递归删除目录.像rmdir(), 如果子文件夹成功删除, removedirs()才尝试它们的父文件夹,直到抛出一个error(它基本上被忽略,因为它一般 ...

  3. [Codeforces671D]Roads in Yusland

    [Codeforces671D]Roads in Yusland Tags:题解 题意 luogu 给定以1为根的一棵树,有\(m\)条直上直下的有代价的链,求选一些链把所有边覆盖的最小代价.若无解输 ...

  4. C++ 三/五法则

    当定义一个类时,我们显式地或隐式地指定了此类型的对象在拷贝.赋值和销毁时做什么.一个类通过定义三种特殊的成员函数来控制这些操作:拷贝构造函数.拷贝赋值运算符和析构函数. 拷贝构造函数定义了当用同类型的 ...

  5. Codeforces 1091E New Year and the Acquaintance Estimation Erdős–Gallai定理

    题目链接:E - New Year and the Acquaintance Estimation 题解参考: Havel–Hakimi algorithm 和 Erdős–Gallai theore ...

  6. java 系统属性

    java.version  Java 运行时环境版本 java.vendor  Java 运行时环境供应商 java.vendor.url  Java 供应商的 URL java.home  Java ...

  7. CentOS 7安装Python3.5

    CentOS 7下安装Python3.5 •安装python3.5可能使用的依赖 yum install openssl-devel bzip2-devel expat-devel gdbm-deve ...

  8. 滑动时候警告:Unable to preventDefault inside passive event listener

    1 前言 在制作2048时,需要在手机端添加滑动检测事件,然后发现控制台有警告,如下: main2048.js:218 [Intervention] Unable to preventDefault ...

  9. elasticsearch索引自动清理

    一 es 基本操作 查看所有的索引文件:  curl -XGET http://localhost:9200/_cat/indices?v GET /_cat/indices?v DELETE /fi ...

  10. Windows&Word 常用快捷键

    Win:显示开始菜单 Win + E:打开文件管理器 Win + D:显示桌面 Win + L:锁定计算机 Win + I:打开设置 Win + M:最小化所有窗口 Alt + F4:1.用来关闭当前 ...