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 < ...
随机推荐
- Windows下搭建HTK
转自:http://blog.csdn.net/yanli0823/article/details/8186382 亲测有效,环境: windows 8.1 perl版本: HTK版本:Hidden ...
- CentOS安装使用git
yum install git yum install git-gui (可选) git config --global user.name "gg" git config --g ...
- How to create PDF files in a Python/Django application using ReportLab
https://assist-software.net/blog/how-create-pdf-files-python-django-application-using-reportlab CONT ...
- 每日英语:A Better Way To Treat Anxiety
Getting up the nerve to order in a coffee shop used to be difficult for 16-year-old Georgiann Steely ...
- 效果非常好的 Jquery弹出层插件 jQuery Sweet alert
介绍款交互性非常不错的jquery弹出层插件,支持消息提示.错误提示.确认框提示等. 交互式体验感非常不错,比如咱们现在体验非常不错的微信支付.支付宝等完成后的效果. 不过本插件至少支持IE9+ Jq ...
- location.href 不响应的解决方法
在某些时候修改元素的值的时候过快会导致失效 1.window.open("","_blank") 代替 不过也是打开新窗口 2.延迟调用location.hr ...
- FreeRTOS基础知识
前面一篇文章介绍了一些命名规范之类的基础知识,但是我觉得还缺少一定前言知识,就是裸机和操作系统有什么区别,为什么我们需要学freertos,因为招聘要求?那么为什么招聘网又会有这个要求呢?所以我们为什 ...
- lua获取喜马拉雅音频地址
参考此文http://blog.csdn.net/zjg555543/article/details/39177971 在Linux下可以直接运行 #!/usr/bin/lua5. --需要luacu ...
- 脚本中出现“+ $'\r' : command not found
脚本中的部分应该是从doc直接拷过来的,造成回车符“\r”出现问题 通过将脚本内容在linux下拷贝一次,就解决了这个问题!
- Android基础总结(一)项目结构,事件
Android项目的目录结构 Activity:应用被打开时显示的界面 src:项目代码 R.java:项目中所有资源文件的资源id Android.jar:Android的jar包,导入此包方可使用 ...