Py学习  »  Elasticsearch

搜索引擎,Elasticsearch Rest API应用

javap • 4 年前 • 304 次点击  

一、 索引

索引命令使用格式: <Rest命令> /<索引库>/<类型>/<ID>
创建
创建索引API允许实例化索引。

# 我们创建的索引具有5个主分片和1个副本(默认值),并且其中包含0个文档
$ curl -XPUT 'http://localhost:9200/angelnode_people/'
#查看创建的索引
$ curl -XGET 'http://localhost:9200/_cat/indices?v'
创建索引

查看全部索引

--
不使用默认的分片数和副本数,指定分片和副本进行创建
现在自定义分片,副本创建(3-shards,2-replicas)

#-H "Content-Type:application/json"  //更换数据传输类型
$ curl -H "Content-Type:application/json" -XPUT 'http://localhost:9200/angelnode_2' -d '{"settings":{"index":{"number_of_shards":3,"number_of_replicas":2}}}'
3-shards,2-replicas索引创建

创建成功

①acknowledged代表是否在集群中成功创建了索引。
②shards_acknowledged代表在超时之前是否为索引中的每个分片启动了所需数量的分片副本。
注意,索引创建成功,但acknowledged或shards_acknowledged仍可能为false。这些值只表明在超时之前这些操作是否已经完成。
如果acknowledged为false,则表明在新创建的索引更新集群状态之前请求超时,但可能之后完成了创建。
如果shards_acknowleged为false,在必要数量的切片(默认正好为主切片)启动之前,甚至集群状态已经更新为成功创建了新索引(即,acknowledged=true),请求超时。
节点数量=分片数量*(副本数量+1)

查询

#单个索引查询
$ curl -XGET 'http://localhost:9200/angelnode_2'
单个索引查询
# 通过在URL中 指定逗号分隔功能,可以过滤返回的信息而仅包括指定信息
$ curl -XGET http://localhost:9200/angelnode_2/_settings,_mapping
查询索引信息结果
井通过使用、_all、或*可以应用于多个索引,或者应用于所有索引。
$ curl -XGET http://localhost:9200/angelnode_*
$ curl -XGET http://localhost:9200/_all
索引统配符查询

索引_all查询

删除

#删除索引
$ curl -XDELETE 'http://localhost:9200/angelnode'
$ curl -XGET 'http://localhost:9200/_cat/indices?v'

删除索引

索引已删除
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52999
 
304 次点击