2.X/1. Getting Started

1-05-3. Pagination

drscg 2017. 9. 30. 20:53

Our preceding empty search told us that 14 documents in the cluster match our (empty) query. But there were only 10 documents in the hits array. How can we see the other documents?

이전의 empty search에서, cluster에는 (empty) query에 일치하는 14개의 document가 있다. 그런데 hits 배열에는 10개의 document만 있었다. 다른 document는 어떻게 볼 수 있을까?

In the same way as SQL uses the LIMIT keyword to return a single "page" of results, Elasticsearch accepts the from and size parameters:

SQL에서, 결과 중 하나의 "page" 를 반환하기 위해, LIMIT keyword를 사용하는 것과 동일한 방식으로, Elasticsearch는 from 과 size 매개변수를 사용한다.

size

Indicates the number of results that should be returned, defaults to 10

몇 개의 결과를 반환할 것인가? default : 10

from

Indicates the number of initial results that should be skipped, defaults to 0

몇 개의 초기 결과를 생략할 것인가? default : 0

If you wanted to show five results per page, then pages 1 to 3 could be requested as follows:

page당 5개의 결과를 보여주려면, page 1 ~ 3은 다음과 같이 request해야 한다.

GET /_search?size=5
GET /_search?size=5&from=5
GET /_search?size=5&from=10

Beware of paging too deep or requesting too many results at once. Results are sorted before being returned. But remember that a search request usually spans multiple shards. Each shard generates its own sorted results, which then need to be sorted centrally to ensure that the overall order is correct.

한 번에 너무 깊은(deep) page나 너무 많은 결과를 request하는 것은 피해야 한다. 결과는 반환되기 전에 정렬된다. 그러나, 검색 결과는 일반적으로 여러 shard에 걸친다는 것을 기억하자. 각 shard는 자신만의 정렬된 결과를 생성한다. 그 다음에 전체적인 순서가 올바른지 보장하기 위해, 중앙에서 정렬되어야 한다.

Tip

In Reindexing Your Data we explain how you can retrieve large numbers of documents efficiently.

Reindexing Your Data에서 많은 수의 document를 효과적으로 가져오는 방법에 대하여 이야기할 것이다.


'2.X > 1. Getting Started' 카테고리의 다른 글

1-05-1. The Empty Search  (0) 2017.09.30
1-05-2. Multi-index, Multitype  (0) 2017.09.30
1-05-4. Search Lite  (0) 2017.09.30
1-06. Mapping and Analysis  (0) 2017.09.30
1-06-1. Exact Values Versus Full Text  (0) 2017.09.30