一、安装(Linux篇)

现在的开源软件越来越成熟,都打好包了,下载后直接解压就可以测试了。

 curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.1.tar.gz
tar -zxvf elasticsearch-6.3..tar.gz
cd elasticsearch-6.3./bin/
./elasticsearch

注意:elasticsearch不允许使用root权限启动,所以使用root下载解压的同学,要chown改变一下文件夹的用户权限。

看到如下信息就说明启动成功了。

[--12T11::,][INFO ][o.e.n.Node               ] [] initializing ...
[--12T11::,][INFO ][o.e.e.NodeEnvironment ] [4LdtI3q] using [] data paths, mounts [[/home (/dev/mapper/cl-home)]], net usable_space [.9gb], net total_space [.9gb], types [xfs]
[--12T11::,][INFO ][o.e.e.NodeEnvironment ] [4LdtI3q] heap size [.7mb], compressed ordinary object pointers [true]
[--12T11::,][INFO ][o.e.n.Node ] [4LdtI3q] node name derived from node ID [4LdtI3q-T2ehl0Z6Xv6cOA]; set [node.name] to override
[--12T11::,][INFO ][o.e.n.Node ] [4LdtI3q] version[6.3.], pid[], build[default/tar/eb782d0/--29T21::.107521Z], OS[Linux/3.10.-.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) -Bit Server VM/1.8.0_112/25.112-b15]
[--12T11::,][INFO ][o.e.n.Node ] [4LdtI3q] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/tmp/elasticsearch.af3cuwkJ, -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, -XX:+PrintTenuringDistribution, -XX:+PrintGCApplicationStoppedTime, -Xloggc:logs/gc.log, -XX:+UseGCLogFileRotation, -XX:NumberOfGCLogFiles=, -XX:GCLogFileSize=64m, -Des.path.home=/home/lings/elastic/elasticsearch-6.3., -Des.path.conf=/home/lings/elastic/elasticsearch-6.3./config, -Des.distribution.flavor=default, -Des.distribution.type=tar]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [aggs-matrix-stats]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [analysis-common]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [ingest-common]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [lang-expression]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [lang-mustache]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [lang-painless]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [mapper-extras]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [parent-join]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [percolator]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [rank-eval]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [reindex]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [repository-url]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [transport-netty4]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [tribe]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [x-pack-core]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [x-pack-deprecation]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [x-pack-graph]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [x-pack-logstash]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [x-pack-ml]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [x-pack-monitoring]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [x-pack-rollup]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [x-pack-security]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [x-pack-sql]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [x-pack-upgrade]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] loaded module [x-pack-watcher]
[--12T11::,][INFO ][o.e.p.PluginsService ] [4LdtI3q] no plugins loaded
[--12T11::,][INFO ][o.e.x.s.a.s.FileRolesStore] [4LdtI3q] parsed [] roles from file [/home/lings/elastic/elasticsearch-6.3./config/roles.yml]
[--12T11::,][INFO ][o.e.x.m.j.p.l.CppLogMessageHandler] [controller/] [Main.cc@] controller ( bit): Version 6.3. (Build 4d0b8f0a0ef401) Copyright (c) Elasticsearch BV
[--12T11::,][DEBUG][o.e.a.ActionModule ] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[--12T11::,][INFO ][o.e.d.DiscoveryModule ] [4LdtI3q] using discovery type [zen]
[--12T11::,][INFO ][o.e.n.Node ] [4LdtI3q] initialized
[--12T11::,][INFO ][o.e.n.Node ] [4LdtI3q] starting ...
[--12T11::,][INFO ][o.e.t.TransportService ] [4LdtI3q] publish_address {127.0.0.1:}, bound_addresses {[::]:}, {127.0.0.1:}
[--12T11::,][WARN ][o.e.b.BootstrapChecks ] [4LdtI3q] max file descriptors [] for elasticsearch process is too low, increase to at least []
[--12T11::,][WARN ][o.e.b.BootstrapChecks ] [4LdtI3q] max virtual memory areas vm.max_map_count [] is too low, increase to at least []
[--12T11::,][INFO ][o.e.c.s.MasterService ] [4LdtI3q] zen-disco-elected-as-master ([] nodes joined)[, ], reason: new_master {4LdtI3q}{4LdtI3q-T2ehl0Z6Xv6cOA}{y7E-EJNzQKq7Xj5-B-okOA}{127.0.0.1}{127.0.0.1:}{ml.machine_memory=, xpack.installed=true, ml.max_open_jobs=, ml.enabled=true}
[--12T11::,][INFO ][o.e.c.s.ClusterApplierService] [4LdtI3q] new_master {4LdtI3q}{4LdtI3q-T2ehl0Z6Xv6cOA}{y7E-EJNzQKq7Xj5-B-okOA}{127.0.0.1}{127.0.0.1:}{ml.machine_memory=, xpack.installed=true, ml.max_open_jobs=, ml.enabled=true}, reason: apply cluster state (from master [master {4LdtI3q}{4LdtI3q-T2ehl0Z6Xv6cOA}{y7E-EJNzQKq7Xj5-B-okOA}{127.0.0.1}{127.0.0.1:}{ml.machine_memory=, xpack.installed=true, ml.max_open_jobs=, ml.enabled=true} committed version [] source [zen-disco-elected-as-master ([] nodes joined)[, ]]])
[--12T11::,][INFO ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [4LdtI3q] publish_address {127.0.0.1:}, bound_addresses {[::]:}, {127.0.0.1:}
[--12T11::,][INFO ][o.e.n.Node ] [4LdtI3q] started
[--12T11::,][WARN ][o.e.x.s.a.s.m.NativeRoleMappingStore] [4LdtI3q] Failed to clear cache for realms [[]]
[--12T11::,][INFO ][o.e.l.LicenseService ] [4LdtI3q] license [d717e767-fe3f-4b36-bc85-cad6dbde3efc] mode [basic] - valid
[--12T11::,][INFO ][o.e.g.GatewayService ] [4LdtI3q] recovered [] indices into cluster_state
[--12T11::,][INFO ][o.e.c.r.a.AllocationService] [4LdtI3q] Cluster health status changed from [RED] to [YELLOW] (reason: [shards started [[customer][], [customer][]] ...]).

二、REST使用示例

1. 查看集群的状态
curl -X GET "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
1531365002 11:10:02 elasticsearch yellow 1 1 10 10 0 0 10 0 - 50.0%
注意这个status的状态是yellow,理想的状态应该是green,原因是没有配置集群。 2. 查看节点的状态
curl -X GET "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 20 57 3 0.07 0.06 0.06 mdi * 4LdtI3q 3. 查看所有索引(类比mysql的库)的状态
curl -X GET 'http://localhost:9200/_cat/indices?v'
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open bank BO1IYzoXSpGGyYP3XKo4bA 5 1 1000 0 475.1kb 475.1kb
yellow open customer -8lF3GAFT1WI43gR9DiYpw 5 1 5 0 17.7kb 17.7kb
有两个索引bank和customer,一个1000条数据,一个有5条数据。 4. 查看索引(customer)的状态
curl -X PUT "localhost:9200/customer?pretty"
{
"error" : {
"root_cause" : [
{
"type" : "resource_already_exists_exception",
"reason" : "index [customer/-8lF3GAFT1WI43gR9DiYpw] already exists",
"index_uuid" : "-8lF3GAFT1WI43gR9DiYpw",
"index" : "customer"
}
],
"type" : "resource_already_exists_exception",
"reason" : "index [customer/-8lF3GAFT1WI43gR9DiYpw] already exists",
"index_uuid" : "-8lF3GAFT1WI43gR9DiYpw",
"index" : "customer"
},
"status" : 400
} 5. 更新(不存在时则增加)索引的document(类比Mysql的行)
curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
"name": "John Doe"
}
'
响应如下:
{
"_index" : "customer",
"_type" : "_doc",
"_id" : "1",
"_version" : 8, //每更新一次版本记录就+1
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 7,
"_primary_term" : 4
} 6. 增加索引的document(和PUT增加的区别就是不用指定document的id,会随机生成一个)
curl -X POST "localhost:9200/customer/_doc?pretty" -H 'Content-Type: application/json' -d'
{
"name": "Jane Doe"
}
'
响应如下:
{
"_index" : "customer",
"_type" : "_doc",
"_id" : "Bu1tjWQBZa8_pSJjP5AF", //随机生成的id
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 8,
"_primary_term" : 4
} 7. 查看指定的document
curl -X GET "localhost:9200/customer/_doc/1?pretty"
响应结果
{
"_index" : "customer",
"_type" : "_doc",
"_id" : "1",
"_version" : 8,
"found" : true,
"_source" : {
"name" : "John Doe"
}
} 8. 删除指定的document
curl -X DELETE "localhost:9200/customer/_doc/B-1ujWQBZa8_pSJjH5CC?pretty"
响应结果:
{
"_index" : "customer",
"_type" : "_doc",
"_id" : "B-1ujWQBZa8_pSJjH5CC",
"_version" : 3,
"result" : "not_found",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 7,
"_primary_term" : 4
} 9. 批量插入文本数据
curl -H "Content-Type: application/json" -XPOST "localhost:9200/bank/_doc/_bulk?pretty&refresh" --data-binary "@/home/lings/accounts.json"
/home/lings/accounts.json为json文件的存放路径 10. 按照account_number升幂排序
curl -X GET "localhost:9200/bank/_search?q=*&sort=account_number:asc&pretty"
完全等效于这个命令
curl -X GET "localhost:9200/bank/_search" -H 'Content-Type: application/json' -d'
{
"query": { "match_all": {} },
"sort": [
{ "account_number": "asc" }
]
}
' 响应结果:
{
"took" : 3, //查询花费了3ms
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1000, //一共有1000条数据
"max_score" : null,
"hits" : [
{
"_index" : "bank",
"_type" : "_doc",
"_id" : "0",
"_score" : null,
"_source" : {
"account_number" : 0,
"balance" : 16623,
"firstname" : "Bradshaw",
"lastname" : "Mckenzie",
"age" : 29,
"gender" : "F",
"address" : "244 Columbus Place",
"employer" : "Euron",
"email" : "bradshawmckenzie@euron.com",
"city" : "Hobucken",
"state" : "CO"
},
"sort" : [
0
]
},
......省略中间数据
{
"_index" : "bank",
"_type" : "_doc",
"_id" : "9",
"_score" : null,
"_source" : {
"account_number" : 9,
"balance" : 24776,
"firstname" : "Opal",
"lastname" : "Meadows",
"age" : 39,
"gender" : "M",
"address" : "963 Neptune Avenue",
"employer" : "Cedward",
"email" : "opalmeadows@cedward.com",
"city" : "Olney",
"state" : "OH"
},
"sort" : [
9 //一共只返回了10个document
]
}
]
}
} 11. 查询住址包含Street单词的所有document
curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": { "match": {"address":"Street"} },
"sort": [
{ "account_number": "desc" }
]
}
'
响应如下:
{
"took" : 9,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 385, //满足条件的385个,总共还是返回10个document
"max_score" : null,
"hits" : [
{
"_index" : "bank",
"_type" : "_doc",
"_id" : "996",
"_score" : null,
"_source" : {
"account_number" : 996,
"balance" : 17541,
"firstname" : "Andrews",
"lastname" : "Herrera",
"age" : 30,
...... 12. 查询住址包含Street单词的降幂排序后的2个document
curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": { "match": {"address":"Street"} },
"sort": [
{ "account_number": "desc" }
],
"size":2
}
'
响应如下:
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 385,
"max_score" : null,
"hits" : [
{
"_index" : "bank",
"_type" : "_doc",
"_id" : "996",
"_score" : null,
"_source" : {
"account_number" : 996,
"balance" : 17541,
"firstname" : "Andrews",
"lastname" : "Herrera",
"age" : 30,
"gender" : "F",
"address" : "570 Vandam Street",
"employer" : "Klugger",
"email" : "andrewsherrera@klugger.com",
"city" : "Whitehaven",
"state" : "MN"
},
"sort" : [
996
]
},
{
"_index" : "bank",
"_type" : "_doc",
"_id" : "994",
"_score" : null,
"_source" : {
"account_number" : 994,
"balance" : 33298,
"firstname" : "Madge",
"lastname" : "Holcomb",
"age" : 31,
"gender" : "M",
"address" : "612 Hawthorne Street",
"employer" : "Escenta",
"email" : "madgeholcomb@escenta.com",
"city" : "Alafaya",
"state" : "OR"
},
"sort" : [
994
]
}
]
}
}

Elasticsearch初探(一)的更多相关文章

  1. Elasticsearch初探

     elasticsearch中的概念同传统数据库的类比如下: Relational DB -> Databases -> Tables -> Rows -> ColumnsEl ...

  2. elasticsearch 安装配置详解

    一.安装 简单的安装与启动于前文ElasticSearch初探(一)已有讲述,这里不再重复说明. 二.启动 1.自带脚本启动 1)bin/elasticsearch,不太任何参数,默认在前端启动 2) ...

  3. Elasticsearch聚合初探——metric篇

    Elasticsearch是一款提供检索以及相关度排序的开源框架,同时,也支持对存储的文档进行复杂的统计--聚合. 前言 ES中的聚合被分为两大类:Metric度量和bucket桶(原谅我英语差,找不 ...

  4. ElasticSearch入门系列(四)分布式初探

    序言:ElasticSearch致力于隐藏分布式系统的复杂性,以下的操作都是在底层自动完成的: 将你的文档分区到不同的容器或者分片(shards),他们可以存在于一个或多个节点中 将分片均匀的分配到各 ...

  5. ES 03 - 初探Elasticsearch的主要配置文件(以6.6.0版本为例)

    目录 1 elasticsearch.yml(ES服务配置) 1.1 Cluster集群配置 1.2 Node节点配置 1.3 Paths路径配置 1.4 Memory内存配置 1.5 Network ...

  6. mysql转ElasticSearch的分析 及JAVA API 初探

    前言 最近工作中在进行一些技术优化,为了减少对数据库的压力,对于只读操作,在程序与db之间加了一层-ElasticSearch.具体实现是db与es通过bin-log进行同步,保证数据一致性,代码调用 ...

  7. ElasticStack学习(六):ElasticSearch搜索初探

    一.ElasticSearch搜索介绍 1.ElasticSearch搜索方式主要分为以下两种: 1).URI Search:此种查询主要是使用Http的Get方法,在URL中使用查询参数进行查询: ...

  8. ElasticStack学习(七):ElasticSearch之Mapping初探

    一.Mapping的概念 1.Mapping类似于数据库中的Schema的定义,作用如下: 1)定义索引中的字段的名称: 2)定义字段的数据类型,例如字符串.数字.日期.布尔等: 3)对每个字段进行倒 ...

  9. ElasticStack学习(八):ElasticSearch索引模板与聚合分析初探

    一.Index Template与Dynamic Template的概念 1.Index Template:它是用来根据提前设定的Mappings和Settings,并按照一定的规则,自动匹配到新创建 ...

随机推荐

  1. spring boot与spring mvc的区别是什么?

    Spring 框架就像一个家族,有众多衍生产品例如 boot.security.jpa等等.但他们的基础都是Spring 的 ioc和 aop ioc 提供了依赖注入的容器 aop ,解决了面向横切面 ...

  2. jconsole监控远程linux tomcat运行情况的配置 (转)

    来自:http://zhumeng8337797.blog.163.com/blog/static/100768914201242494649455/ 步骤如下: 1.编辑tomcat/bin/cat ...

  3. Bootstrap定制开发

    Bootstrap作为目前很受欢迎的前端框架,越来越多的网站开始使用基于Bootstrap框架进行开发. 1.定制开发方法 (1)Bootstrap定制开发可以使用LESS和Grunt实现定制化 (2 ...

  4. 《Unix&Linux大学教程》学习笔记一:历史与常识

     “为什么说Unix/Linux是自由的:         因为我们可以自己组装一个操作系统:Unix/Linux内核+其他实用工具+编程工具+GUI         因为我们可以自由地获取开源工作者 ...

  5. OpenERP7测试手记之 - EMail配置 转

    转自http://blog.sina.com.cn/s/blog_6d5929a00101b74y.html 在OpenERP中进行Email配置要注意以下几点: 1.如下面两个图,公司的“电子邮件” ...

  6. python在linux的报错集锦

    1. 报错提示 /usr/lib/python2.7/site-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 ...

  7. LeetCode] binaryTreePaths

    class Solution { public: void binaryPath(TreeNode* root, vector<string>& result, string pa ...

  8. GDAL添加ECW格式支持

    目录 GDAL添加ECW格式支持 ECW 下载ECW JPEG SDK 在Unix平台构建支持ECW的GDAL 二进制ECW SDK和GCC >= 5.1 在Linux上构建的教程 在Windo ...

  9. 如何查看 EBS 环境上的 INV RUP 版本号

    select 'Application Environment: '|| i.instance_name || ', Host: '|| i.host_name ||', Application Re ...

  10. [转载]Ubuntu下Git服务器安装与配置

    原文地址:Ubuntu下Git服务器安装与配置作者:F民抄 1. 安装 1.1 安装Git-Core: sudo apt-get install git-core 1.2 安装 Gitosis sud ...