ElasticSearch(十五) _search api 分页搜索及deep paging性能问题

1、分页搜索

语法:

size,from

GET /_search?size=10
GET /_search?size=10&from=0
GET /_search?size=10&from=20
GET /index/type/_search
{
  "query": { "match_all": {} },
  "from": 1,
  "size": 1
}

实际操作:

查看共有5条数据:

GET /test_index/test_type/_search
"hits" : {
    "total" : 7,
    "max_score" : 1.0,

我们假设将这7条数据分成3页,每一页是3条数据,来实验一下这个分页搜索的效果

第一页:

GET /test_index/test_type/_search?from=0&size=3

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 7,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "test_index",
        "_type" : "test_type",
        "_id" : "10",
        "_score" : 1.0,
        "_source" : {
          "test_field1" : "test1",
          "test_field2" : "test2"
        }
      },
      {
        "_index" : "test_index",
        "_type" : "test_type",
        "_id" : "12",
        "_score" : 1.0,
        "_source" : {
          "num" : 1,
          "tags" : [ ]
        }
      },
      {
        "_index" : "test_index",
        "_type" : "test_type",
        "_id" : "6",
        "_score" : 1.0,
        "_source" : {
          "test_field" : "test test"
        }
      }
    ]
  }
}

第二页:

GET /test_index/test_type/_search?from=3&size=3

{
  "took" : 7,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 7,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "test_index",
        "_type" : "test_type",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "test_field" : "replaced test2"
        }
      },
      {
        "_index" : "test_index",
        "_type" : "test_type",
        "_id" : "Baq9WWgBjIP9BXE3vrJ2",
        "_score" : 1.0,
        "_source" : {
          "test_field" : "auto-generate id test"
        }
      },
      {
        "_index" : "test_index",
        "_type" : "test_type",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "test_field1" : "test1",
          "test_field2" : "bulk test1"
        }
      }
    ]
  }
}

第三页:

GET /test_index/test_type/_search?from=6&size=3

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 7,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "test_index",
        "_type" : "test_type",
        "_id" : "11",
        "_score" : 1.0,
        "_source" : {
          "num" : 0,
          "tags" : [ ]
        }
      }
    ]
  }
}

 

2、深度搜索deep paging的性能问题

 

 

posted @ 2019-01-18 15:13  加肥猫咪  阅读(...)  评论(...编辑  收藏