title: Why search performance is difference between from&size and search&after
body: <p>There are hundreds of millions of documents in my index. When I search, I find that search&amp;after is much slower than from&amp;size。 Use from&amp;size，search is quick，took several ms return，but use search after，it took 20 seconds。My search result is sort by time and key(a keyword copy of _id) ，Why？what's the difference?
  search cmd:</p>
  <pre><code>{
      &quot;query&quot;:{
          &quot;bool&quot;:{
              &quot;filter&quot;:[
                  {
                      &quot;query_string&quot;:{
                          &quot;query&quot;:&quot;*&quot;
                      }
                  },
                  {
                      &quot;range&quot;:{
                          &quot;__time__&quot;:{
                              &quot;gte&quot;:1324958207,
                              &quot;lte&quot;:1724958207
                          }
                      }
                  }
              ]
          }
      },
      &quot;size&quot;:10,
      &quot;sort&quot;:[
          {
              &quot;__time__&quot;:{
                  &quot;order&quot;:&quot;desc&quot;
              }
          },
          {
              &quot;__key__&quot;:{
                  &quot;order&quot;:&quot;desc&quot;
              }
          }
      ],
      &quot;search_after&quot;:[
          1630594662000,
          &quot;6130e666-2-67e9e3-f5-1&quot;
      ],
      &quot;profile&quot;:true
  }
  </code></pre>
  <p>profile:</p>
  <pre><code>{&quot;searches&quot;:[
                      {
                          &quot;query&quot;:[
                              {
                                  &quot;type&quot;:&quot;BoostQuery&quot;,
                                  &quot;description&quot;:&quot;(ConstantScore(DocValuesFieldExistsQuery [field=__time__]))^0.0&quot;,
                                  &quot;time_in_nanos&quot;:45722536283,
                                  &quot;breakdown&quot;:{
                                      &quot;set_min_competitive_score_count&quot;:0,
                                      &quot;match_count&quot;:0,
                                      &quot;shallow_advance_count&quot;:0,
                                      &quot;set_min_competitive_score&quot;:0,
                                      &quot;next_doc&quot;:45722241414,
                                      &quot;match&quot;:0,
                                      &quot;next_doc_count&quot;:410919487,
                                      &quot;score_count&quot;:0,
                                      &quot;compute_max_score_count&quot;:0,
                                      &quot;compute_max_score&quot;:0,
                                      &quot;advance&quot;:19517,
                                      &quot;advance_count&quot;:39,
                                      &quot;score&quot;:0,
                                      &quot;build_scorer_count&quot;:78,
                                      &quot;create_weight&quot;:14271,
                                      &quot;shallow_advance&quot;:0,
                                      &quot;create_weight_count&quot;:1,
                                      &quot;build_scorer&quot;:261081
                                  },
                                  &quot;children&quot;:[
                                      {
                                          &quot;type&quot;:&quot;DocValuesFieldExistsQuery&quot;,
                                          &quot;description&quot;:&quot;DocValuesFieldExistsQuery [field=__time__]&quot;,
                                          &quot;time_in_nanos&quot;:16571715415,
                                          &quot;breakdown&quot;:{
                                              &quot;set_min_competitive_score_count&quot;:0,
                                              &quot;match_count&quot;:0,
                                              &quot;shallow_advance_count&quot;:0,
                                              &quot;set_min_competitive_score&quot;:0,
                                              &quot;next_doc&quot;:16571493898,
                                              &quot;match&quot;:0,
                                              &quot;next_doc_count&quot;:410919487,
                                              &quot;score_count&quot;:0,
                                              &quot;compute_max_score_count&quot;:0,
                                              &quot;compute_max_score&quot;:0,
                                              &quot;advance&quot;:15074,
                                              &quot;advance_count&quot;:39,
                                              &quot;score&quot;:0,
                                              &quot;build_scorer_count&quot;:78,
                                              &quot;create_weight&quot;:517,
                                              &quot;shallow_advance&quot;:0,
                                              &quot;create_weight_count&quot;:1,
                                              &quot;build_scorer&quot;:205926
                                          }
                                      }
                                  ]
                              }
                          ],
                          &quot;rewrite_time&quot;:116538,
                          &quot;collector&quot;:[
                              {
                                  &quot;name&quot;:&quot;PagingFieldCollector&quot;,
                                  &quot;reason&quot;:&quot;search_top_hits&quot;,
                                  &quot;time_in_nanos&quot;:30851166561
                              }
                          ]
                      }
                  ],
                  &quot;aggregations&quot;:[
  
                  ]
              }
  </code></pre>