天天看點

初識搜尋引擎_分頁搜尋,以及deep_paging性能問題深度圖解揭秘

1、如何使用es進行分頁搜尋的文法

size,from

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

分頁的上機實驗

GET test_index/test_type/_search
           

運作結果

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

我們發現有5條資料,現在我們假設把這5條資料分成2頁,每頁3條資料,來實驗分頁搜尋的效果。

第一頁:

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

運作結果

{
  "took": 21,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 5,
    "max_score": 1,
    "hits": [
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "8",
        "_score": 1,
        "_source": {
          "num": 1,
          "tags": []
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "2",
        "_score": 1,
        "_source": {
          "test_field": "test2"
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "6",
        "_score": 1,
        "_source": {
          "test_field1": "test1",
          "test_field2": "test123"
        }
      }
    ]
  }
}
           

第二頁

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

運作結果

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 5,
    "max_score": 1,
    "hits": [
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "1",
        "_score": 1,
        "_source": {
          "test_field": "test123"
        }
      },
      {
        "_index": "test_index",
        "_type": "test_type",
        "_id": "3",
        "_score": 1,
        "_source": {
          "test_field": "test3"
        }
      }
    ]
  }
}
           

第一頁:id=8,2,6

第二頁:id=1,3

2、什麼是deep paging問題,為什麼會産生這個問題,它的底層原理是什麼?

初識搜尋引擎_分頁搜尋,以及deep_paging性能問題深度圖解揭秘

繼續閱讀