0
<form action="/search" method="GET" id="passparms">

First I use this way to pass the params,then push it into function

url(r'^search$', search.mysearch)

and now my function like this:

def search(request):
    request.encoding = 'utf-8'
    product, suggestion = searchbykw(request)
    paginator = Paginator(product, 21)
    page = request.GET.get('page')
    try:
        product = paginator.page(page)
    except PageNotAnInteger:
        product = paginator.page(1)
    except EmptyPage:
        product = paginator.page(paginator.num_pages)
    return render(request, "shop.html",'suggestion': suggestion[0] if suggestion else '',})

right now my url is like

http://127.0.0.1:3453/search?brand=&category=

when I use Python Pagination, the url becomes

http://127.0.0.1:3453/search?page=2

Read a lot on Python Pagination, still no clue. Please help me and thank you for your help.

CCCXXX
  • 1
  • 1

1 Answers1

0

You can use the official python package for Elasticsearch and the out of the box scanfunction that will handle efficiently all the work for you. Here's the link to the package https://elasticsearch-py.readthedocs.io/en/master/helpers.html#scan

Otherwise you need to use "from" and "size" in your query:

{"from":startPosition, 
 "size": numberOfElementsToGet,
 "query": {..}
}

Doing the latter is not optimized as ES will scan, all the elements before the startPosition at each query. So if you are doing start 0, size 10 and start 10, size 10, ES internally will scan 10 and 20 elements.

ML_TN
  • 727
  • 6
  • 16