02.Elasticsearch入门
1.Elasticsearch基本概念
2.使用Restful API简单操作ElasticSearch
[lizhiwei@localhost ~]$ curl -XGET http://192.168.110.100:9200
{
"status" : 200,
"name" : "node000",
"cluster_name" : "elasticsearchTest",
"version" : {
"number" : "1.7.2",
"build_hash" : "e43676b1385b8125d647f593f7202acbd816e8ec",
"build_timestamp" : "2015-09-14T09:49:53Z",
"build_snapshot" : false,
"lucene_version" : "4.10.4"
},
"tagline" : "You Know, for Search"
}
[lizhiwei@localhost ElasticSearch]$ curl -XPUT http://192.168.110.100:9200/test -d @data.json
{"acknowledged":true}
---------------------------------------------data.json内容
{
"settings" : {
"index" : {
"number_of_shards" : "4",
"number_of_replicas" : "2"
}
}
}
[lizhiwei@localhost ElasticSearch]$ curl -XPUT http://192.168.110.100:9200/test -d @data.json
{"acknowledged":true}
---------------------------------------------data.json内容
{
"settings" : {
"index" : {
"number_of_shards" : "4",
"number_of_replicas" : "1"
}
},
"mappings" : {
"DocType001" : {
"_source" : {
"enabled" : false
},
"properties" : {
"field1" : {
"type" : "string",
"index" : "not_analyzed"
},
"field2" : {
"type" : "string",
"store" : "yes"
}
}
}
}
}
[lizhiwei@localhost ElasticSearch]$ curl -XDELETE http://192.168.110.100:9200/test
{"acknowledged":true}
[lizhiwei@localhost ElasticSearch]$ curl -XPOST http://192.168.110.100:9200/test/People?pretty -d '{ "tag" : "bad" }'
{
"_index" : "test",
"_type" : "People",
"_id" : "AVBRAKASiFg2t1Ow-SEW",
"_version" : 1,
"created" : true
}
[lizhiwei@localhost ElasticSearch]$ curl -XPOST http://192.168.110.100:9200/test/People/3?pretty -d '{ "tag" : "bad" }'
{
"_index" : "test",
"_type" : "People",
"_id" : "3",
"_version" : 1,
"created" : true
}
# 查询所有的index和type的记录
curl -XGET http://IP:9200/_search?pretty
# 查询某个index下所有type的记录
curl -XGET http://IP:9200/<index>/_search?pretty
# 查询某个index下某个type下所有的记录
curl -XGET http://IP:9200/<index>/<type>/_search?pretty
# 使用参数查询所有的记录
curl -XGET http://IP:9200/_search?q=tag:bad&pretty;
# 使用参数查询某个index下的所有记录
curl -XGET http://IP:9200/<index>/_search?q=tag:bad&pretty;
# 使用参数查询某个index下某个type下所有的记录
curl -XGET http://IP:9200/<index>/<type>/_search?q=tag:bad&pretty;
# 使用JSON参数查询所有的记录,-d代表一个JSON格式的对象
curl -XGET http://IP:9200/_search?pretty -d '{ "query" : { "term" : { "tag" : "bad" } } }'
# 使用JSON参数查询某个index下的所有记录
curl -XGET http://IP:9200/<index>/_search?pretty -d '{ "query" : { "term" : { "tag" : "bad" } } }'
# 使用JSON参数查询某个index下某个type下所有的记录
curl -XGET http://IP:9200/<index>/<type>/_search?pretty -d '{ "query" : { "term" : { "tag" : "bad" } } }'
[lizhiwei@localhost ElasticSearch]$ curl -XGET http://192.168.110.100:9200/test/People/_search?pretty
{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [ {
"_index" : "test",
"_type" : "People",
"_id" : "AVBRBKcOiFg2t1Ow-SEy",
"_score" : 1.0,
"_source":{ "tag" : "bad" }
}, {
"_index" : "test",
"_type" : "People",
"_id" : "3",
"_score" : 1.0,
"_source":{ "tag" : "bad" }
} ]
}
}
[lizhiwei@localhost ElasticSearch]$ curl -XPUT http://192.168.110.100:9200/test/People/3?pretty -d '{ "tag" : "good" }'
{
"_index" : "test",
"_type" : "People",
"_id" : "3",
"_version" : 3,
"created" : false
}
[lizhiwei@localhost ElasticSearch]$ curl -XDELETE http://192.168.110.100:9200/test/People/3?pretty
{
"found" : true,
"_index" : "test",
"_type" : "People",
"_id" : "3",
"_version" : 4
}
[lizhiwei@localhost ElasticSearch]$ curl -XGET http://192.168.110.100:9200/_cluster/health?pretty
{
"cluster_name" : "elasticsearchTest",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 4,
"number_of_data_nodes" : 4,
"active_primary_shards" : 7,
"active_shards" : 14,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0
}
3.常用的Restful API
# 检查集群健康:
curl -XGET http://127.0.0.1:9200/_cluster/health?pretty
# 关闭整个集群:
curl -XPOST http://127.0.0.1:9200/_cluster/nodes/_shutdown
# 关闭单台节点:
curl -XPOST http://127.0.0.1:9200/_cluster/nodes/{node.name}/_shutdown
# 查看集群节点:
curl -XGET http://127.0.0.1:9200/_cluster/nodes?pretty
# 查看集群状态:
curl -XGET http://127.0.0.1:9200/_cluster/state?pretty
# 查看节点状态:
curl -XGET http://127.0.0.1:9200/_nodes/stats?pretty
# 查看本机节点:
curl -XGET http://127.0.0.1:9200/_nodes/_local?pretty
# 查看集群节点信息:
curl -XGET http://127.0.0.1:9200/_cluster/state/nodes
# 查看索引映射:
curl -XGET http://127.0.0.1:9200/.marvel-kibana/_mapping?pretty
以上所有查询都可以针对json节点的子节点进行查询,关键词如:settings, os, process, jvm, thread_pool, network, transport, http , plugins
例如:
curl -XGET 'http://localhost:9200/_nodes?pretty'
curl -XGET 'http://localhost:9200/_nodes/process?pretty'
curl -XGET 'http://localhost:9200/_nodes/os?pretty'
curl -XGET 'http://localhost:9200/_nodes/settings?pretty'
-------------------------------------------------------------------------------------------------------------------------------
02.Elasticsearch入门的更多相关文章
- 《读书报告 -- Elasticsearch入门 》-- 安装以及简单使用(1)
<读书报告 – Elasticsearch入门 > 第一章 Elasticsearch入门 Elasticsearch是一个实时的分布式搜索和分析引擎,使得人们可以在一定规模上和一定速度上 ...
- 全文搜索引擎Elasticsearch入门实践
全文搜索引擎Elasticsearch入门实践 感谢阮一峰的网络日志全文搜索引擎 Elasticsearch 入门教程 安装 首先需要依赖Java环境.Elasticsearch官网https://w ...
- springboot整合elasticsearch入门例子
springboot整合elasticsearch入门例子 https://blog.csdn.net/tianyaleixiaowu/article/details/72833940 Elastic ...
- ElasticSearch入门-搜索如此简单
搜索引擎我也不是很熟悉,但是数据库还是比较了解.可以把搜索理解为数据库的like功能的替代品.因为like有以下几点不足: 第一.like的效率不行,在使用like时,一般都用不到索引,除非使用前缀匹 ...
- ElasticSearch入门知识扫盲
ElasticSearch 入门介绍 tags: 第三方 lucene [toc] 1. what Elastic Search(ES)是什么 全文检索和lucene 全文检索 优点:高效,准确,分词 ...
- 《读书报告 -- Elasticsearch入门 》--简单使用(2)
<读书报告 – Elasticsearch入门 > ' 第四章 分布式文件存储 这章的主要内容是理解数据如何在分布式系统中存储. 4.1 路由文档到分片 创建一个新文档时,它是如何确定应该 ...
- ElasticSearch入门 附.Net Core例子
1.什么是ElasticSearch? Elasticsearch是基于Lucene的搜索引擎.它提供了一个分布式,支持多租户的全文搜索引擎,它具有HTTP Web界面和无模式JSON文档. Elas ...
- ElasticSearch入门点滴
这是Elasticsearch-6.2.4 版本系列的第一篇: ElasticSearch入门 第一篇:Windows下安装ElasticSearch ElasticSearch入门 第二篇:集群配置 ...
- Elasticsearch Elasticsearch入门指导
Elasticsearch入门指导 By:授客 QQ:1033553122 1. 开启elasticsearch服务器 1 2. 基本概念 2 <1> 集群(Cluster) 2 < ...
随机推荐
- vim中不同模式的帮助信息的查找
vim的模式有多种,比如normal(普通模式),insert(插入模式),command(命令行模式),visual(可视化模式).相同的命令和快捷键在不同的模式下功能是不一样的,因此帮助信息也是分 ...
- 基于FPGA的PCIe接口实现(具体讲解了数据流向)
时间:2014-12-09 来源:西安电子科技大学电子工程学院 作者:姜 宁,陈建春,王 沛,石 婷 摘要 PCI Express是一种高性能互连协议,被广泛应用于网络适配.图形加速器.网络存储.大数 ...
- PHP中把stdClass Object转array的几个方法
方法一: 复制代码代码如下: //PHP stdClass Object转array function object_array($array) { if(is_object($array)) { $ ...
- Redis 学习笔记四 Mysql 与Redis的同步实践
一.测试环境在Ubuntu kylin 14.04 64bit 已经安装Mysql.Redis.php.lib_mysqludf_json.so.Gearman. 点击这里查看测试数据库及表参考 本文 ...
- HDU 2844 Coin 多重背包
Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- flume+kafka
这里演示在单机fulume环境下,kafka作为source ,chanel , sink时三种情况 下面的测试都是基于下面的基本的配置文件进行修改的 a1.sources = r1 a1.sinks ...
- phpadmin 装了6666端口只能在IE打开,在阿里云改了 开放端口85好了
phpadmin 装了6666端口只能在IE打开,在阿里云改了 开放端口85好了 非常用端口谷歌浏览器识别不了phpadmin
- Jquery仿IGoogle实现可拖动窗口
google可谓是ajax的特效用的淋漓尽致,google suggest, google map,igoogle 可拖动窗口等等...今天要做一个网站的类似效果,与编程人生的站长沟通了一下,仿照iG ...
- 关于Unity的C#基础学习(二)
一.Debug的使用 int a=3; Debug.Log("a="+a); 二.整数的定义 int m; Debug.Log(m); //C#比C更严谨,没有初始化的变量打印出 ...
- 使用HashMap,put()表示放置元素,get()表示取元素
SortedSet可自动为元素排序. SortedSet的实现类是TreeSet:它的作用是字为添加到TreeSet中的元素排序. 与HashSet不同,TreeSet并不需要实现HashCode() ...