Reputation: 4426
I am new to elasticsearch and at least for the flask extension (flask-elasticsearch) the documentation is very bad. Any help is much appreachiated.
I have a elasticsearch query which looks like this
res = es.search(index="user-index", from_=(page-1)*10, size=10, body={"query": {"match_all": {}}})
I query the user table and want only 10 results. Now I still have to get the actual table rows. So I query them like this
list_of_ids = []
for hit in res['hits']['hits']:
list_of_ids.append(hit["_id"])
search_result = models.User.query.filter(models.User.id.in_(list_of_ids)).paginate(page, 10, False)
as you can see I am using the paginate() function. However, since I passed a list of 10 ids into the query, the paginate function does not know about the total number of results in the search query. So the paginate function can't work this way...
I could just do all the paginate functionality by myself, but I was wondering whether there is a nice way to keep the paginate functionality and somehow link it with the elastic search? thanks carl
Upvotes: 3
Views: 1578
Reputation: 4426
I found a solution... its possible to just assign the relevant pagination values like
search_result.total = res['hits']['total']
search_result.page = page
cheers
Upvotes: 2