一、安装(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. 牛客网-《剑指offer》-斐波那契数列

    题目:http://www.nowcoder.com/practice/c6c7742f5ba7442aada113136ddea0c3 C++ class Solution { public: in ...

  2. 使用electron+Js开发夸平台(Linux、Win、Mac)的桌面应用程序

    一.开源地址: https://github.com/electron/electron 二.官方网站: https://electron.atom.io/ 三.案例

  3. 使用Selenium+PhantomJS实现网页内容加载(包括网页后期Ajax出来的结果)

    一.需求 需要Nuget下面的库: 二.代码 class Program { static void Main(string[] args) { TestPhantomJsDriver(); } pr ...

  4. eclipse 运行简单JAVA程序事例

    开发JAVA已经有一段时间了,不过要运行JAVA程序,还是在命令行敲命令,很不方便,很麻烦,突然想到eclipse应该也有这个功能,于是百度了一下,将步骤晒出来,供大家参考. 1.创建JAVA工程 单 ...

  5. Payment相关逻辑

    payment相关逻辑 付款有手动付款和计划程序自动付款两种,照例先列出涉及到的概念 付款方式 - PaymentTypes - 现金,支票,信用卡,等等 记账类型 - Ledger_AccTrans ...

  6. 斯坦福《机器学习》Lesson1-3感想-------3、线性回归二

    从上一篇可知.在监督学习里最重要的就是确定假想函数h(θ),即通过使得代价函数J(θ)最小,从而确定h(θ). 上一篇通过梯度下降法求得J(θ)最小,这篇我们将使用矩阵的方法来解释. 1.普通最小二乘 ...

  7. windows下安装mysql5.6

    1.   下载 http://dev.mysql.com/downloads/windows/installer/5.6.html 2.   安装 我们采用自定义安装模式:选择32位或64位 默认即可 ...

  8. Aerospike系列:6:AerospikeTools & Utilities

    1:Aerospike Query Language类似于SQL命令.可以用来管理索引和用户自定义函数,也可以测试大多数数据库的功能. [root@localhost ~]#aql OPTIONS - ...

  9. Webwork【01】Webwork与 Struct 的前世今生

    Struts 1是全世界第一个发布的MVC框架,它由Craig McClanahan在2001年发布,该框架一经推出,就得到了世界上Java Web开发者的拥护,经过长达6年时间的锤炼,Struts ...

  10. 索引范围扫描(INDEX RANGE SCAN)

    索引范围扫描(INDEX RANGE SCAN)适用于所有类型的B树索引,当扫描的对象是唯一性索引时,此时目标SQL的where条件一定是范围查询(谓词条件为 BETWEEN.<.>等): ...