文档API

source:https://www.elastic.co/guide/en/elasticsearch/reference/6.4/docs.html

这章简单介绍一下es的数据数值模型,接下来是对crud api的详细描述

简单的文档API:

indexAPI(索引):

索引api用来增加后者更新一个json的数据文档到指定的索引之中,让他能被查到,下面的操作是写入一条文档到twitter索引中,type指定为“_doc”

curl -X PUT "localhost:9200/twitter/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}
'

返回下面结果

{
    "_shards" : { "total" : 2, "failed" : 0, "successful" : 2 }, "_index" : "twitter", "_type" : "_doc", "_id" : "1", "_version" : 1, "_seq_no" : 0, "_primary_term" : 1, "result" : "created" }

_shards提供了索引操作中复制过程相关的信息

total:使用了多少分片(主副)

successful :索引操作成功的复制了多少分片

failed:索引操作失败的副本分片列表

索引操作的成功标志是successful最少是1

注意:副本分片可能不会在索引操作成功的时候就开始(默认情况下,只有主分片被需要,但是这种模式也可以更改)。这个例子中,total的数量与number_of_replicas设置有关,successful与分片开始的时候有关(主分片),如果没有失败情况,failed就是0

猜你喜欢

转载自www.cnblogs.com/supermanwx/p/11991333.html