{ "status" : 200, "name" : "Captain Zero", "cluster_name" : "elasticsearch", "version" : { "number" : "1.5.0", "build_hash" : "544816042d40151d3ce4ba4f95399d7860dc2e92", "build_timestamp" : "2015-03-23T14:30:58Z", "build_snapshot" : false, "lucene_version" : "4.10.4" }, "tagline" : "You Know, for Search"}./elasticsearch –d #在后台运行Elasticsearch ./elasticsearch -d -Xmx2g -Xms2g #后台启动,启动时指定内存大小(2G) ./elasticsearch -d -Des.logger.level=DEBUG #可以在日志中打印出更加详细的信息。
配置elasticsearch的集群名称,默认是elasticsearch。elasticsearch会自动发现在同一网段下的集群名为elasticsearch的主机,如果在同一网段下有多个集群,就可以用这个属性来区分不同的集群。生成环境时建议更改。
节点名,默认随机指定一个name列表中名字,该列表在elasticsearch的jar包中config文件夹里name.txt文件中,其中有很多作者添加的有趣名字,大部分是漫威动漫里面的人物名字。生成环境中建议更改以能方便的指定集群中的节点对应的机器
指定该节点是否有资格被选举成为node,默认是true,elasticsearch默认集群中的第一台启动的机器为master,如果这台机挂了就会重新选举master。
指定该节点是否存储索引数据,默认为true。如果节点配置node.master:false并且node.data: false,则该节点将起到负载均衡的作用
设置默认索引分片个数,默认为5片。经本人测试,索引分片对ES的查询性能有很大的影响,在应用环境,应该选择适合的分片大小。
设置默认索引副本个数,默认为1个副本。此处的1个副本是指index.number_of_shards的一个完全拷贝;默认5个分片1个拷贝;即总分片数为10。
设置配置文件的存储路径,默认是es根目录下的config文件夹。
设置索引数据的存储路径,默认是es根目录下的data文件夹,可以设置多个存储路径,用逗号隔开。
设置临时文件的存储路径,默认是es根目录下的work文件夹。
设置日志文件的存储路径,默认是es根目录下的logs文件夹
设置插件的存放路径,默认是es根目录下的plugins文件夹
设置为true来锁住内存。因为当jvm开始swapping时es的效率会降低,所以要保证它不swap,可以把ES_MIN_MEM和ES_MAX_MEM两个环境变量设置成同一个值,并且保证机器有足够的内存分配给es。同时也要允许elasticsearch的进程可以锁住内存,linux下可以通过ulimit -l unlimited命令。
设置绑定的ip地址,可以是ipv4或ipv6的,默认为0.0.0.0。
设置其它节点和该节点交互的ip地址,如果不设置它会自动判断,值必须是个真实的ip地址。
这个参数是用来同时设置bind_host和publish_host上面两个参数。
设置节点间交互的tcp端口,默认是9300。
设置是否压缩tcp传输时的数据,默认为false,不压缩。
设置对外服务的http端口,默认为9200。
设置内容的最大容量,默认100mb
是否使用http协议对外提供服务,默认为true,开启。
gateway的类型,默认为local即为本地文件系统,可以设置为本地文件系统,分布式文件系统,hadoop的HDFS,和amazon的s3服务器,其它文件系统的设置。
设置集群中N个节点启动时进行数据恢复,默认为1。
设置初始化数据恢复进程的超时时间,默认是5分钟。
设置这个集群中节点的数量,默认为2,一旦这N个节点启动,就会立即进行数据恢复。
初始化数据恢复时,并发恢复线程的个数,默认为4。
添加删除节点或负载均衡时并发恢复线程的个数,默认为4。
设置数据恢复时限制的带宽,如入100mb,默认为0,即无限制。
设置这个参数来限制从其它分片恢复数据时最大同时打开并发流的个数,默认为5。
设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4)
设置集群中自动发现其它节点时ping连接超时时间,默认为3秒,对于比较差的网络环境可以高点的值来防止自动发现时出错。
设置是否打开多播发现节点,默认是true。
设置集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点。
threadpool: search: type: fixed min: 60 max: 80 queue_size: 1000// 配置es服务器的执行查询操作时所用线程池,fix固定线程数的线程池。
index : store: type: memory// 表示索引存储在内存中,当然es不太建议这么做。经本人测试,做查询时,使用内存索引并不会比正常的索引快。
index.mapper.dynamic: false// 禁止自动创建mapping。默认情况下,es可以根据数据类型自动创建mapping。配置成这样,可以禁止自动创建mapping的行为。至于什么是mapping,在之后的博文中再介绍。
index.query.parse.allow_unmapped_fields: false // 不能查找没有在mapping中定义的属性
基础知识注意:查询是ES的核心。作为一个先进的搜索引擎,ES中提供了多种查询接口。本篇仅仅会涉及查询API的结构,而具体如何使用ES所提供的各种查询API,会在接下来的博文中做详细介绍。
查看集群(Cluster)信息相关API注意。文中的示例代码里面包含了用户注释的文字,就是 # 号后面的文字。运行代码时,请注意删除这些注释。
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks 1440206633 18:23:53 elasticsearch green 1 1 0 0 0 0 0 0
epoch | t,time | seconds since 1970-01-01 00:00:00 timestamp | ts,hms,hhmmss | time in HH:MM:SS cluster | cl | cluster name status | st | health status node.total | nt,nodeTotal | total number of nodes node.data | nd,nodeData | number of nodes that can store datashards | t,sh,shards.total,shardsTotal | total number of shards pri | p,shards.primary,shardsPrimary | number of primary shards relo | r,shards.relocating,shardsRelocating | number of relocating nodes init | i,shards.initializing,shardsInitializing | number of initializing nodes unassign | u,shards.unassigned,shardsUnassigned | number of unassigned shards pending_tasks | pt,pendingTasks | number of pending tasks
curl -XPUT "localhost:9200/index_test" -d ' # 注意这里的'号{ "settings": { "index": { "number_of_replicas": "1", # 设置复制数 "number_of_shards": "5" # 设置主分片数 } }, "mappings": { # 创建mapping "test_type": { # 在index中创建一个新的type(相当于table) "properties": { "name": { # 创建一个字段(string类型数据,使用普通索引) "type": "string", "index": "not_analyzed" }, "age": { "type": "integer" } } } }}'curl -XPUT 'localhost:9200/index_test/_mapping/test_type' -d ' { "test_type": { # 注意,这里的test_type与url上的test_type名保存一致 "properties": { "name": { "type": "string", "index": "not_analyzed" }, "age": { "type": "integer" } } } }'{ "test_type": { # 注意,这里的test_type与json文件名必须一致 "properties": { "name": { "type": "string", "index": "not_analyzed" }, "age": { "type": "integer" } } } }curl -XPUT 'localhost:9200/index_test/test_type/1?pretty' -d ' # 这里的pretty参数的作用是使得返回的json显示地更加好看。1是文档的id值(唯一键)。{ "name": "zhangsan", "age" : "12"}'curl -XPOST 'localhost:9200/index_test/test_type/1?pretty' -d ' # 这里的1必须是索引中已经存在id,否则就会变成新增文档操作{ "name": "lisi", "age" : "12"}'
curl -XDELETE 'localhost:9200/index_test/test_type/1?pretty' # 这里的1必须是索引中已经存在id
curl -XGET 'localhost:9200/index_test/test_type/1?pretty'
{ "cat.health": { "documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-health.html", # 该文档对应的官方站点 "methods": ["GET"], "url": { # url部分可选 "path": "/_cat/health", "paths": ["/_cat/health"], "parts": { }, "params": { "local": { "type" : "boolean", "description" : "Return local information, do not retrieve the state from master node (default: false)" }, "master_timeout": { "type" : "time", "description" : "Explicit operation timeout for connection to master node" }, "h": { "type": "list", "description" : "Comma-separated list of column names to display" }, "help": { "type": "boolean", "description": "Return help information", "default": false }, "ts": { "type": "boolean", "description": "Set to false to disable timestamping", "default": true }, "v": { "type": "boolean", "description": "Verbose mode. Display column headers", "default": true } } }, "body": null }}| 欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |