Elastic Search RESTful API

ES是一个服务,通过webservice即可完成集群管理与搜素引擎使用。

1.集群管理

ip:port :默认端口号是9200。es服务正常的话就会见到图1-1.


图1-1 

ip:port/_cluster/health :集群的健康状况。

ip:port/_cluster/nodes/_shutdown : 关掉整个集群。

ip:port/_cluster/nodes/nodeName/_shutdown:关掉指定的node。

2.文档操作

2.1增

ip:port/indexName/type/   POST  :增加文档。见图2-1.

图2-1 增添文档成功

2.2删

ip:port/indexName/type/docID  DELETE  :删除指定id的文档

图2-2 删除指定id的文档

2.3改


2.4查

ip:port/indexName/type/docID GET:按照doc的id来查。见下图。


图2-4 按照docID来查文档

2.5 搜索

2.5.1 GET方法

ip:port/indexName/_search?q=field:content GET:根据关键词搜索文档


图2-5 搜索
由图2-5可见,took表示花费时间,timed_out表示是否超时。

2.5.2 POST方法

POST方法可以携带更多的信息,比如:
{
	"query": {
		"filtered": {
			"query": {
				"bool": {
					"should": [{
						"query_string": {
							"query": "+source:online +countPerMinute:[50 TO 99]",
							"lowercase_expanded_terms": false
						}
					}]
				}
			},
			"filter": {
				"bool": {
					"must": [{
						"range": {
							"@timestamp": {
								"from": 1461845220944,
								"to": 1461846120944
							}
						}
					}]
				}
			}
		}
	},
	"fields": ["theKey"],
	"size": 1000
}

3.索引设置

3.1 创建

3.1.1 自动创建

ip:port/indexName  PUT  :创建名为indexName的索引。

3.1.2 定义索引结构并创建

ip:port/indexName  POST :创建名为indexName的索引。
mapping的意思是 schema mapping,用于定义索引结构。
post内容示例见下:
{
	"mappings": {
		"essay": {
			"properties": {
				"id": {
					"type": "long",
					"store": "yes",
					"precision_step": "0"
				},
				"title": {
					"type": "string",
					"store": "yes",
					"index": "analyzed"
				},
				"content": {
					"type": "string",
					"store": "yes",
					"index": "analyzed"
				}
			}
		}
	}
}

3.2 查看索引结构

ip:port/indexName  GET:查看名为indexName的索引结构。

3.3 开启与关闭

ip:port/indexName/_open:开启索引。
ip:port/indexName/_close:关闭索引。关闭后就不能对这个索引进行读写。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值