Elasticsearch索引:

简介

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

创建索引

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

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

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

修改索引

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

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

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

删除索引

1
DELETE /test_index

获取索引

123456789101112131415161718192021222324252627
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"      }    }  }}

过滤查询

123456789101112131415161718192021222324252627
索引的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"          }        }      }    }  }}

关闭索引

映射管理

增加映射

12345678910111213141516171819202122232425
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}可以接受逗号(,)分隔符,也可以使用

12
GET  test_index2/_mapping/{string}GET /test_index2/_mapping/log,user

判断存在

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

1
HEAD test_index2/secilog

索引别名

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

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

修改别名

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

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

删除别名

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

查询别名

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

ElasticSearch索引相关推荐

  1. elasticsearch 索引 red 状态恢复 green

    ES集群状态.节点.索引及基本查询 一.elasticsearch 索引 red 状态恢复 green 错误原因 由于CPU占用过高或者有部分节点的分片不可用,未被分配: 解决: 重新分配未被分配的分 ...

  2. Elasticsearch索引生命周期管理方案

    点击上方蓝色"方志朋",选择"设为星标" 回复"666"获取独家整理的学习资料! 一.前言 在 Elasticsearch 的日常中,有很多 ...

  3. python将ElasticSearch索引数据读入pandas dataframe实战

    python将ElasticSearch索引数据读入pandas dataframe实战 # 导入基础包和库 import pandas as pdpd.set_option('display.max ...

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

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

  5. Elasticsearch索引原理

    最近在参与一个基于Elasticsearch作为底层数据框架提供大数据量(亿级)的实时统计查询的方案设计工作,花了些时间学习Elasticsearch的基础理论知识,整理了一下,希望能对Elastic ...

  6. elasticsearch 索引_Elasticsearch系列---索引管理

    概要 Elasticsearch让索引创建变得非常简单,只要索引一条新的数据,索引会自动创建出来,但随着数据量的增加,我们开始有了索引优化和搜索优化的需求之后,就会发现自动创建的索引在某些方面不能非常 ...

  7. elasticsearch索引结构和配置优化

    elasticsearch索引结构和配置简单调优. 1.搜索时对特定字段设置更高权值,以弱化相关性低的字段 例如:我们在搜索时认为标题对我们更重要就可以对标题提高匹配权重 boolQuery.must ...

  8. sql server cdc 清理_基于CDC技术的ElasticSearch索引同步机制

    概述 ElasticSearch作为一个基于Lucene的搜索引擎被广泛应用于各种应用系统,比如电商.新闻类.咨询类网站.在使用ElasticSearch开发应用的过程中,一个非常重要的过程是将数据导 ...

  9. ElasticSearch-Hadoop:从Hadoop到ElasticSearch索引产品视图计数和客户顶部搜索查询

    这篇文章涵盖了如何使用ElasticSearch-Hadoop从Hadoop系统读取数据并在ElasticSearch中对其进行索引. 它涵盖的功能是在最近n天中为每个客户的产品浏览量计数和热门搜索查 ...

  10. delphi报列表索引越界怎么处理_图解Elasticsearch索引机制,此篇带你领悟新世界...

    前言 随着Elastic的上市,ELK不仅在互联网大公司得到长足的发展,而且在各个中小公司都得到非常广泛的应用,甚至连"婚庆网站"都开始使用Elasticsearch了.随之而来的 ...

最新文章

  1. AI,被“横扫记录”反噬?
  2. 【CTS】几个serialno失败项
  3. 收到猎头信息的一些感想
  4. C语言用位运算构建特定的二进制数
  5. [BUUCTF-pwn]——[BJDCTF 2nd]ydsneedgirlfriend2
  6. php面试带项目_PHP面试常用算法(推荐)
  7. day7——集合,深浅copy
  8. 4怎么放大字体_win8.1系统如何放大所有字体?
  9. Spring 事务初始化源码分析
  10. 查看80端口连接状态
  11. 【笔试/面试】—— linux(rpm)
  12. 防止重复提交表单的两种方法
  13. 数值代数中的数学原理及其证明(一)
  14. R语言将数值转换为比例
  15. bzoj 1208 宠物收养所 Splay入门
  16. 【夏季养生以心为大】
  17. 正态分布随机数 C语言,正态分布随机数生成算法
  18. 激活函数(1)Sigmoid激活函数
  19. ESP32在WIN7下USB调试串口驱动安装 解决USB JTAG/serial debug unit (Interface 0)无法安装驱动的问题
  20. 你都用 Python 来做什么 学Python能做什么

热门文章

  1. Javascript中document.execCommand()的用法
  2. Flask学习之基础知识与功能
  3. #if、#if defined 的使用
  4. [Java][内存模型]
  5. linux上NFS性能参数
  6. 【转】【MySql】Waiting for table metadata lock原因分析
  7. uva 10891 - Game of Sum
  8. textread读取记事本文件
  9. (zt)Flash与C++交互
  10. 如何在 JavaScript 中实现拖放