Elasticsearch之基本使用
这里大概解答下各个目录、配置文件的作用:
| 目录 | 配置文件 | 描述 |
|---|---|---|
| bin | 放置脚本文件,如启动脚本 elasticsearch, 插件安装脚本等。 | |
| config | elasticserch.yml | elasticsearch 配置文件,如集群配置、jvm 配置等。 |
| jdk | java 运行环境 | |
| data | path.data | 数据持久化文件 |
| lib | 依赖的相关类库 | |
| logs | path.log | 日志文件 |
| modules | 包含的所有 ES 模块 | |
| plugins | 包含的所有已安装的插件 |
注意点:
有些童鞋的机器内存可能不够,就需要修改 JVM 参数,配置文件路径为 config/jvm.options,ES V7.1 版本默认为 1g, 老版本为2g, 你可以自行修改。
Xmx 和Xms 数值请设置相同;
Xmx 不要超过机器内存的 50%;
内存总量不要超过 30GB, 参见官方文档 https://www.elastic.co/cn/blog/a-heap-of-trouble;
1. 查看集群健康情况
http://localhost:9200/_cat
=^.^=
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/tasks
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates
http://localhost:9200/_cat/health?v epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1586056370 03:12:50 main-search green 9 7 50 25 0 0 0 0 - 100.0%
说明:v是用来要求在结果中返回表头
状态值说明
Green - everything is good (cluster is fully functional),即最佳状态
Yellow - all data is available but some replicas are not yet allocated (cluster is fully functional),即数据和集群可用,但是集群的备份有的是坏的
Red - some data is not available for whatever reason (cluster is partially functional),即数据和集群都不可用
2. 查看所有节点
/_cat/nodes
3. 查看所有索引
http://localhost:9200/_cat/indices?v green open .monitoring-kibana-7-2020.04.01 601ZG1FRQY688qAp3O1uaQ 1 1 8640 0 5.3mb 2.6mb
green open .monitoring-kibana-7-2020.04.02 J89ViHaQQC697nQ5gqMXtg 1 1 8639 0 5.3mb 2.6mb
green open .monitoring-kibana-7-2020.04.03 C-Sp-DDpTmWMZzdk1E3Wbw 1 1 3242 0 2.1mb 1mb
green open .monitoring-es-7-2020.04.05 3NT3phueS-qf76XDtwYKcw 1 1 34632 59482 60.6mb 31mb
4. 创建索引
PUT /customer?pretty
5. 添加文档到索引
curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
"name": "John Doe"
}
'
6. 查询所有文档
GET /customer/_search?q=*&sort=name:asc&pretty json格式:
GET /customer/_search
{
"query": { "match_all": {} },
"sort": [
{"name": "asc" }
]
}
索引管理
1. 创建索引
PUT user
{
"settings" : {
"index" : {
"number_of_shards" : 3,
"number_of_replicas" : 2
}
}
} 设置索引的分片数为3,备份数为2。注意:在ES中创建一个索引类似于在数据库中建立一个数据库(ES6.0之后类似于创建一个表) 说明:
默认的分片数是5到1024
默认的备份数是1
索引的名称必须是小写的,不可重名
简写:
PUT twitter
{
"settings" : {
"number_of_shards" : 3,
"number_of_replicas" : 2
}
}
2. 创建mapping映射
注意:在ES中创建一个mapping映射类似于在数据库中定义表结构,即表里面有哪些字段、字段是什么类型、字段的默认值等;也类似于solr里面的模式schema的定义
PUT twitter
{
"settings" : {
"index" : {
"number_of_shards" : 3,
"number_of_replicas" : 2
}
},
"mappings" : {
"type1" : {
"properties" : {
"field1" : { "type" : "text" }
}
}
}
}
3. 创建索引时加入别名定义
PUT twitter
{
"aliases" : {
"alias_1" : {},
"alias_2" : {
"filter" : {
"term" : {"user" : "kimchy" }
},
"routing" : "kimchy"
}
}
}
4. 索引创建完成返回值
{
"acknowledged": true, // 索引创建成功
"shards_acknowledged": true, // 分片+副本创建,启动成功
"index": "logs" // 索引名称
}
5. 查看索引的定义信息
1) GET /twitter,可以一次获取多个索引(以逗号间隔) 获取所有索引 _all 或 用通配符*
{
"logs": {
"aliases": { },
"mappings": { },
"settings": {
"index": {
"creation_date": "1586100271307",
"number_of_shards": "1",
"number_of_replicas": "1",
"uuid": "50kKYpnoRX-p6rwxXuo2Jw",
"version": {
"created": "7050099"
},
"provided_name": "logs"
}
}
}
}
2)索引设置项
GET /twitter/_settings
3)数据定义
GET /twitter/_mapping
6. 删除索引
DELETE /twitter 说明: 可以一次删除多个索引(以逗号间隔) 删除所有索引 _all 或 通配符 *
7. 判断索引是否存在
HEAD twitter HTTP status code 表示结果 404 不存在 , 200 存在
8. 修改索引的settings信息
索引的设置信息分为静态信息和动态信息两部分。静态信息不可更改,如索引的分片数。动态信息可以修改。 REST 访问端点:
/_settings 更新所有索引的。
{index}/_settings 更新一个或多个索引的settings。 详细的设置项请参考:https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules.html#index-modules-settings
9. 修改备份数
PUT /twitter/_settings
{
"index" : {
"number_of_replicas" : 2
}
}
10. 设置回默认值,用null
PUT /twitter/_settings
{
"index" : {
"refresh_interval" : null
}
}
11. 设置索引的读写
index.blocks.read_only:设为true,则索引以及索引的元数据只可读
index.blocks.read_only_allow_delete:设为true,只读时允许删除。
index.blocks.read:设为true,则不可读。
index.blocks.write:设为true,则不可写。
index.blocks.metadata:设为true,则索引元数据不可读写。
12. 索引模板
在创建索引时,为每个索引写定义信息可能是一件繁琐的事情,ES提供了索引模板功能,让你可以定义一个索引模板,模板中定义好settings、mapping、以及一个模式定义来匹配创建的索引。
注意:模板只在索引创建时被参考,修改模板不会影响已创建的索引
12.1 新增/修改名为tempae_1的模板,匹配名称为te* 或 bar*的索引创建:
PUT _template/template_1
{
"index_patterns": ["te*", "bar*"],
"settings": {
"number_of_shards": 1
},
"mappings": {
"type1": {
"_source": {
"enabled": false
},
"properties": {
"host_name": {
"type": "keyword"
},
"created_at": {
"type": "date",
"format": "EEE MMM dd HH:mm:ss Z YYYY"
}
}
}
}
}
13. 查看索引模版
GET /_template/template_1
GET /_template/temp*
GET /_template/template_1,template_2
GET /_template
14. 删除模版
DELETE /_template/template_1
15. Open/Close Index 打开/关闭索引
POST /my_index/_close
POST /my_index/_open 说明: 关闭的索引不能进行读写操作,几乎不占集群开销。
关闭的索引可以打开,打开走的是正常的恢复流程。
16. 索引添加新字段
{
"properties": {
"publish_date": {
"type": "keyword"
}
}
}
Elasticsearch之基本使用的更多相关文章
- Elasticsearch之java的基本操作一
摘要 接触ElasticSearch已经有一段了.在这期间,遇到很多问题,但在最后自己的不断探索下解决了这些问题.看到网上或多或少的都有一些介绍ElasticSearch相关知识的文档,但个人觉得 ...
- Elasticsearch 5.0 中term 查询和match 查询的认识
Elasticsearch 5.0 关于term query和match query的认识 一.基本情况 前言:term query和match query牵扯的东西比较多,例如分词器.mapping ...
- 以bank account 数据为例,认识elasticsearch query 和 filter
Elasticsearch 查询语言(Query DSL)认识(一) 一.基本认识 查询子句的行为取决于 query context filter context 也就是执行的是查询(query)还是 ...
- Ubuntu 14.04中Elasticsearch集群配置
Ubuntu 14.04中Elasticsearch集群配置 前言:本文可用于elasticsearch集群搭建参考.细分为elasticsearch.yml配置和系统配置 达到的目的:各台机器配置成 ...
- ElasticSearch 5学习(10)——结构化查询(包括新特性)
之前我们所有的查询都属于命令行查询,但是不利于复杂的查询,而且一般在项目开发中不使用命令行查询方式,只有在调试测试时使用简单命令行查询,但是,如果想要善用搜索,我们必须使用请求体查询(request ...
- ElasticSearch 5学习(9)——映射和分析(string类型废弃)
在ElasticSearch中,存入文档的内容类似于传统数据每个字段一样,都会有一个指定的属性,为了能够把日期字段处理成日期,把数字字段处理成数字,把字符串字段处理成字符串值,Elasticsearc ...
- .net Elasticsearch 学习入门笔记
一. es安装相关1.elasticsearch安装 运行http://localhost:9200/2.head插件3.bigdesk插件安装(安装细节百度:windows elasticsear ...
- 自己写的数据交换工具——从Oracle到Elasticsearch
先说说需求的背景,由于业务数据都在Oracle数据库中,想要对它进行数据的分析会非常非常慢,用传统的数据仓库-->数据集市这种方式,集市层表会非常大,查询的时候如果再做一些group的操作,一个 ...
- 如何在Elasticsearch中安装中文分词器(IK+pinyin)
如果直接使用Elasticsearch的朋友在处理中文内容的搜索时,肯定会遇到很尴尬的问题--中文词语被分成了一个一个的汉字,当用Kibana作图的时候,按照term来分组,结果一个汉字被分成了一组. ...
- jar hell & elasticsearch ik 版本问题
想给es 安装一个ik 的插件, 我的es 是 2.4.0, 下载了一个版本是 1.9.5, [2016-10-09 16:56:26,248][INFO ][node ] [node-2] init ...
随机推荐
- 文件包含与PHP伪协议
文件包含与伪协议 一.无任何过滤措施的文件包含漏洞:(ctfshow-web78): 1.data://协议: ?file=data://text/plain,<?php system('tac ...
- 2023年2月中国数据库排行榜:OTO新格局持续三月,人大金仓、AnalyticDB排名创新高
玉兔迎春至,榜单焕新颜. 2023年2月,兔年开年的 墨天轮中国数据库流行度排行 火热出炉,本月共有259个数据库参与排名,排行榜样式去掉了较上月和半年前得分差的数据显示,更加聚焦各产品之间的排名变化 ...
- 06 - react的类组件中的状态state render函数 this指向问题 事件绑定
// 注册事件 import ReactDom from "react-dom" import { Component } from "react" // 类组 ...
- 小程序的json文件
json文件是页面的描述文件,对本页面的窗口外观设置,页面的配置可以覆盖全局的配置 (app.json);
- vue-template-admin 模板
1. 替换登录页的样式 2. settings.js 3. layout 文件夹 4. store 文件夹 4.1 app.js
- kotlin基础——>基本数据类型、控制流、返回和跳转
1.对于数字的定义,支持java 8的下划线分割的方式 val a = 1_2_3 与 val a = 123 是相同的 2.如果要指定数字类型有两种方式 val a : Float = 1 或者 v ...
- Android复习(一)基础知识
1. 现在可以使用 Kotlin.Java 和 C++ 语言编写 Android 应用 2.Android四大组件依然坚挺,这是基础并且没有改变的迹象 Activity 服务 广播接收器 内容提供程序 ...
- tekton初次安装报错“containers with incomplete status: [place-tools]”
报错内容 在按照官方部署方式部署完毕以后,执行第一个taskrun的时候就报错了,报错如下 Status: Conditions: Last Transition Time: 2022-08-08T0 ...
- AOT漫谈专题(第四篇): C#程序如何编译成Native代码
一:背景 1. 讲故事 大家都知道所谓的.NET Native AOT即通过AOT编译器直接将C#代码编译成机器码,大家也习惯用C/C++的编译过程来类比,都是静态编译本质上都差不多,这篇我们借助工具 ...
- python多进程完成模拟支付
#!/usr/bin/python # -*- coding: UTF-8 -*- '''@auther :mr.qin @IDE:pycharm''' from tool.Common import ...