Elastic Search RESTful API

    xiaoxiao2026-01-26  7

    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:关闭索引。关闭后就不能对这个索引进行读写。 相关资源:python入门教程(PDF版)
    最新回复(0)