Elasticsearch学习笔记:整理
下载Elasticsearch
mkdir /home/es
cd /home/es
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.zip
解压:
unzip elasticsearch-6.0.0.zip
因为是开箱即用,所以不需要安装
切换到bin目录下
cd /home/es/elasticsearch6.0.0/bin
执行
./elasticsearch -d (-d是后台运行,如果不输入,当前Console会被锁死,不能进行其他操作,执行Ctrl + c,可关闭Elasticsearch;如果执行-d,则无法看见执行的详细信息)
即可运行
如果需要覆盖集群或者节点的名字,则在启动时,添加参数:
./elasticsearch --cluster.name my_cluster_name --node.name my_node_name -d
要检查集群健康,我们将使用_cat API。需要事先记住的是,我们的节点HTTP的端口是9200:
curl 'localhost:9200/_cat/health?v'
如下:
============================================================
[root@localhost ~]# curl '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
1512571194 22:39:54 elasticsearch green 1 1 0 0 0 0 0 0 - 100.0%
[root@localhost ~]#
============================================================
绿色:一切正常(集群功能齐全)
黄色:所有的数据都是可用的,但是某些复制没有被分配(集群功能是完备的)
红色:因为某些原因,某些数据不可用。
注意,即使是集群状态是红色的,集群仍然是部分可用的(它仍然会利用可用的分片来响应搜索请求),但是可能你需要尽快修复它,因为你有丢失的数据
获得节集群中的节点列表:
curl 'localhost:9200/_cat/nodes?v'
============================================================
[root@localhost ~]# curl 'localhost:9200/_cat/nodes?v'
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
127.0.0.1 11 96 1 0.00 0.04 0.05 mdi * qnnd6ME
============================================================
显示索引
curl 'localhost:9200/_cat/indices?v'
============================================================
[root@localhost ~]# curl 'localhost:9200/_cat/indices?v'
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open customer n8UenwhWTr-8Y84WPsU92g 5 1 1 0 4.7kb 4.7kb
============================================================
创建索引
curl -XPUT 'localhost:9200/[索引名]?[返回json格式:pretty 美化的格式]'
例如curl -XPUT 'localhost:9200/myindex?pretty'
============================================================
[root@localhost ~]# curl -XPUT 'localhost:9200/myindex?pretty'
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "myindex"
}
============================================================
插入数据
curl -XPUT 'localhost:9200/[索引名]/[类型名]/[指定id]' -d '{"key":"value","key":"value",...}'
例如:
curl -XPUT 'localhost:9200/myindex/external/1' -d '{"firstName":"John","LastName":"Smith"}'
注意:-d之前,必需要空格!!!!
但是执行之后,出现错误:
============================================================
[root@localhost ~]# curl -XPUT 'localhost:9200/myindex/external/1' -d '{"firstName":"John","LastName":"Smith"}'
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}[root@localhost ~]#
============================================================
格式化输入依然报错
============================================================
bash-4.2$ curl -XPUT 'localhost:9200/myindex/external/1?pretty' -d '
{
"firstName":"John"
"LastName":"Smith"
}'
{
"error" : "Content-Type header [application/x-www-form-urlencoded] is not supported",
"status" : 406
}
============================================================
这个问题,是在报文Content-type的参数:application/x-www-form-urlencoded不支持Json发送。需要改成application/Json
所以需要添加参数 ; -H 'Content-Type: application/json'
:::::Content-Type现有类型不支持JSON等格式传递
curl -XPUT 'localhost:9200/myindex/external/1' -H 'Content-Type: application/json' -d '{"firstName":"John","LastName":"Smith"}'
curl -XPUT 'localhost:9200/myindex/external/1?pretty' -H 'Content-Type: application/json' -d '
{
"firstName":"John",
"LastName":"Smith"
}'
============================================================
[root@localhost ~]# curl -XPUT 'localhost:9200/myindex/external/1?pretty' -H 'Content-Type: application/json' -d '
> {
> "firstName":"John",
> "LastName":"Smith"
> }'
{
"_index" : "myindex",
"_type" : "external",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
============================================================
取出索引:
curl -XGET 'localhost:9200/myindex/external/1?pretty'
============================================================
[root@localhost ~]# curl -XGET 'localhost:9200/myindex/external/1?pretty'
{
"_index" : "myindex",
"_type" : "external",
"_id" : "1",
"_version" : 1,
"found" : true,
"_source" : {
"firstName" : "John",
"LastName" : "Smith"
}
}
============================================================
_source部分,就是我们添加的数据
_id是之前添加的索引id
删除索引 curl -XDELETE 'localhost:9200/myindex?pretty'
============================================================
[root@localhost ~]# curl -XDELETE 'localhost:9200/myindex?pretty'
{
"acknowledged" : true
}
============================================================
转载于:https://www.cnblogs.com/ZDF64/p/7992663.html
Elasticsearch学习笔记:整理相关推荐
- 【mysql学习笔记整理】
/*mysql学习笔记整理*/ /*常用的数据库操作对象*/ #库的操作 #创建 #数据库的创建 USE mysql; CREATE DATABASE db_x; #删除 #删除数据库 DROP DA ...
- Deep Learning(深度学习)学习笔记整理系列之(五)
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...
- Deep Learning(深度学习)学习笔记整理系列之(二)
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...
- python eval 入门_Python学习笔记整理3之输入输出、python eval函数
Python学习笔记整理3之输入输出.python eval函数 来源:中文源码网 浏览: 次 日期:2018年9月2日 Python学习笔记整理3之输入输出.python eval函数 ...
- Deep Learning(深度学习)学习笔记整理系列之(八)
Deep Learning(深度学习)学习笔记整理系列之(八) 分类: Deep Learning 机器学习 Linux驱动2013-04-10 11:4257652人阅读评论(25)收藏举报 ...
- Deep Learning(深度学习)学习笔记整理系列三
Deep Learning(深度学习)学习笔记整理系列 声明: 1)该Deep Learning的学习系列是整理自网上很大牛和机器学习专家所无私奉献的资料的.具体引用的资料请看参考文献.具体的版本声明 ...
- Deep Learning(深度学习)学习笔记整理(二)
本文整理了网上几位大牛的博客,详细地讲解了CNN的基础结构与核心思想,欢迎交流 [1]Deep learning简介 [2]Deep Learning训练过程 [3]Deep Learning模型之: ...
- java反射 pdf_java反射学习笔记整理.pdf
java反射学习笔记整理.pdf 还剩 15页未读, 继续阅读 下载文档到电脑,马上远离加班熬夜! 亲,很抱歉,此页已超出免费预览范围啦! 如果喜欢就下载吧,价低环保! 内容要点: Java 反射笔记 ...
- 天猫整站SSM-后台分类管理-增加(做个人学习笔记整理用)
天猫整站SSM-后台分类管理-增加(做个人学习笔记整理用) CategoryController: request.getSession().getServletContext()// 获取的是pag ...
- 天猫整站SSM-分页-总结(做个人学习笔记整理用)
天猫整站SSM-分页-herf(做个人学习笔记整理用) 先写Page.java package com.how2java.tmall.util;public class Page {private i ...
最新文章
- Android 解析imei
- DL之paddlepaddle:百度深度学习框架paddlepaddle飞桨的简介、安装、使用方法之详细攻略
- 【实用】表维护视图SM30增加自定义按钮的实现
- 十二、深入JavaScript中的Date
- Flex4_HttpService组件
- html右侧分为两个框架,html – 两个框架一个滚动条
- 前端开发 巨大banner的首页设计 0228 需另行设计
- DMAR(DMA remapping)与 IOMMU
- arduino水温度传感器数字显示_液晶显示屏应用示例以及程序详解
- 《从零开始走进FPGA》导读
- 新技能 get —— 如何校验 md5(windows)
- 如何在苹果Mac中使用“启动安全性实用工具”?
- 谈谈js中的异步编程。
- cad横断面图转文本
- FFmpeg开发(1)从mp4中提取aac音频
- 不用 VIP 也能高速下载!迅雷 11 新版抢先体验 2T迅雷离线云盘
- SH-SSS丨《端到端音视频说话人日志网络》论文线上分享
- Real-Time Rendering——5.2.2 Punctual Lights精准光
- python中response对象的方法_django HttpResponse对象 - 刘江的django教程
- Flutter 功能最全的JsonToDart工具