本文档为您介绍使用阿里云Elasticsearch(简称ES)服务检索文档的方法。

通过Kibana控制台访问阿里云ES,执行以下命令检索文档。
  • 指定索引、类型和文档ID进行检索。
    GET /my_index/my_type/1
    检索成功后,返回如下结果:
    {
      "_index" : "my_index",
      "_type" : "my_type",
      "_id" : "1",
      "_version" : 3,
      "_seq_no" : 2,
      "_primary_term" : 1,
      "found" : true,
      "_source" : {
        "title" : "One World",
        "tags" : [
          "ruby"
        ],
        "post_date" : "2009-11-15T13:00:00"
      }
    }
  • 指定索引和类型进行检索。
    GET /my_index/my_type/_search
    检索成功后,返回如下结果:
    {
      "took" : 11,
      "timed_out" : false,
      "_shards" : {
        "total" : 5,
        "successful" : 5,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : 3,
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "my_index",
            "_type" : "my_type",
            "_id" : "2",
            "_score" : 1.0,
            "_source" : {
              "title" : "Two",
              "tags" : [
                "ruby"
              ],
              "post_date" : "2009-11-15T14:00:00"
            }
          },
          {
            "_index" : "my_index",
            "_type" : "my_type",
            "_id" : "1",
            "_score" : 1.0,
            "_source" : {
              "title" : "One World",
              "tags" : [
                "ruby"
              ],
              "post_date" : "2009-11-15T13:00:00"
            }
          },
          {
            "_index" : "my_index",
            "_type" : "my_type",
            "_id" : "3",
            "_score" : 1.0,
            "_source" : {
              "title" : "Three",
              "tags" : [
                "ruby"
              ],
              "post_date" : "2009-11-15T15:00:00"
            }
          }
        ]
      }
    }
  • 指定索引进行检索。
    GET /my_index/_search
    检索成功后,返回如下结果:
    {
      "took" : 44,
      "timed_out" : false,
      "_shards" : {
        "total" : 5,
        "successful" : 5,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : 3,
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "my_index",
            "_type" : "my_type",
            "_id" : "2",
            "_score" : 1.0,
            "_source" : {
              "title" : "Two",
              "tags" : [
                "ruby"
              ],
              "post_date" : "2009-11-15T14:00:00"
            }
          },
          {
            "_index" : "my_index",
            "_type" : "my_type",
            "_id" : "1",
            "_score" : 1.0,
            "_source" : {
              "title" : "One World",
              "tags" : [
                "ruby"
              ],
              "post_date" : "2009-11-15T13:00:00"
            }
          },
          {
            "_index" : "my_index",
            "_type" : "my_type",
            "_id" : "3",
            "_score" : 1.0,
            "_source" : {
              "title" : "Three",
              "tags" : [
                "ruby"
              ],
              "post_date" : "2009-11-15T15:00:00"
            }
          }
        ]
      }
    }