Elasticsearch 单文档 API的使用之二(获取文档)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_27868061/article/details/84943769

示例:

GET /spring-elasticsearch-demo/person/1 HTTP/1.1
Host: localhost:9200
Content-Type: application/json
cache-control: no-cache
Postman-Token: 5b200229-505b-45bb-9349-a2b23e1d8e67

{
    "_index": "spring-elasticsearch-demo",
    "_type": "person",
    "_id": "1",
    "_version": 4,
    "found": true,
    "_source": {
        "id": "1",
        "name": "天天向左",
        "description": "这是天天向下",
        "age": 24,
        "create": 1535760000001
    }
}
GET /spring-elasticsearch-demo/person/4 HTTP/1.1
Host: localhost:9200
Content-Type: application/json
cache-control: no-cache
Postman-Token: 07a70aea-c212-4868-ac84-49aeee0752ff

{
    "_index": "spring-elasticsearch-demo",
    "_type": "person",
    "_id": "4",
    "found": false
}

get API允许根据其id从索引中获取类型化的JSON文档。

属性 描述
_index 索引名称
_person 类型名称
_id 文档ID
_version 文档版本
found 是否找到文档
_source 源文档

默认情况下,get API是实时的,并且不受索引刷新率的影响(当数据对搜索可见时)。 如果文档已更新但尚未刷新,则get API将就地发出刷新调用以使文档可见。 这也将使上次刷新后其他文档发生变化。 为了禁用实时GET,可以将realtime参数设置为false。

1._source

可以使用_source查询参数禁用_source字段的返回

GET /spring-elasticsearch-demo/person/1?_source=false HTTP/1.1
Host: localhost:9200
Content-Type: application/json
cache-control: no-cache
Postman-Token: 4bd68447-5be8-4053-9cb9-5d3a9cc38889

{
    "_index": "spring-elasticsearch-demo",
    "_type": "person",
    "_id": "1",
    "_version": 4,
    "found": true
}

也可以直接获取_source字段内容

GET /spring-elasticsearch-demo/person/1/_source HTTP/1.1
Host: localhost:9200
Content-Type: application/json
cache-control: no-cache
Postman-Token: 01932464-b7e5-40f9-a27d-8566b69c1eee

{
    "id": "1",
    "name": "天天向左",
    "description": "这是天天向下",
    "age": 24,
    "create": 1535760000001
}

猜你喜欢

转载自blog.csdn.net/qq_27868061/article/details/84943769