If I have a PFQuery that will search through every user but I limit the results to 3 users, will that query search through every user and then give me 3 users? Or will the query pause/stop once 3 people have been found?
Thanks!
The query will stop searching once it finds what you set as your PFQuery's .limit.
And if you want to have pages of three users, you can use the .skip property, e.g. .skip = pageNumber * 3.
Related
I got parent index users and child purchase. Purchase has field purchase_count it is number of purchase made by user, for example first purchase of some user will be with purchase_count = 1, second with 2 etc.
I want to make query to get total number of users, number of users who had first purchase, number of users who had second etc. For example All: 100, 1: 10, 2: 6, 3: 3 etc..
I know how to do it in two requests, first get count of all users next term aggregation of purchases based on purchase_count field, but can I do it somehow in single query?
There is a datatype in Elasticsearch called parent-join or parent-child previously: https://www.elastic.co/guide/en/elasticsearch/reference/current/parent-join.html
That datatype needs to be in a single index. There are no joins across indices in Elasticsearch.
You probably want to look into parent-join for your usecase, but you'll have to restructure your data to reside in a single index.
I have few filters on the view page and want to show the count that matches the given conditions. Like on the product search result I have Free Shipping filter. I need the count of records matching my filters in the total record not just in the current page.
Explanation:
Suppose In the result set I have 100 records with pagination 20/page, 40 of them has free_shipping = 1. I want to show like Free Shipping(40). Currently, I do $products->where('free_shipping', 1)->count() but this gives me the result matching only in viewed records.
How can I get the total number of matching records regardless of pagination?
Thanks in advance
if Laravel Pagination is used then you can use the total() method.
Example :
$products->total();
Need some advice and help from you!
Two questions.
how can I retrieve a list of patient resources with 30 _counts and sorted by last modified date? I don't have any searching parameters such as identifier, family and given;
since my application in browser is a single page application, when the user scroll down and all the first 30 patients have been shown, I will make another call to get the next 30 patients. I don't need the first 30 patients and just want the records from 31 to 60. What parameters should I used in this paging search? Do we have something like "?_count=30&_page=2". Similarly, if I need the page 100, I don't want the servers sending me the first 99 pages.
Thanks in advance.
Autorun
GET [baseUrl]/Patient?_count=30&sort=_lastUpdated
The response will be a Bundle. Look at the Bundle.link with a Bundle.link.relation of "next". The Bundle.link.url will be the URL to use to get the next "page" of content. The format of the URL is undefined and will be server-specific.
Be aware that _count only constrains the base resource. If you query Patient and do a _revinclude on Observation, you'll get 30 patients - but you'll also get all the observations for all 30 of those patients - which could be 10k+ rows in your result set - so be careful with _include and _revinclude.
I'm new to Elasticsearch and I need to execute a complex query, but I need some help.
Here is my use case:
I would like to recommend a new place to each of my users everyday.
However:
The place must be opened this week day
The chosen place must be near of the user (closer places have higher score)
The place should not be one of the last 10 places a user have already been/suggested (if a place has already been visited by a user in his last 10 visits, this place should have a lower score)
My first guess is to have 2 documents types as follow:
user_history
user_id
place_id
date
place
place_id
opening_days (array with week days the place opens)
location geo position of the place
Given a user with position [lat, lon] and id user_1, what could be the search query to execute to retrieve X places sorted by score? (better score is near of user and not in the 10 last places a user have already been).
This query seems to be a basic but I can't figure out how to "mix" data from user_history and from place to get places I want.
But that's not all!
With this query, if I want to attribute to each user a place I need 3 steps:
retrieve all users (with their position)
for each user, search for the best place
once I have this place, add it to the user_history
This seems very time consuming task. Is it possible to simplify it with less Elasticsearch queries?
For instance, having something like this:
retrieving for each user his best place (with 1 query, search for all users and find them the best place)
add the place to the history
Or event better:
retrieving for each user his best place and add it to the history (with 1 query, perform all the 3 tasks above)
I don't know if it's possible to create queries that complex. That's why I need your help to tell me if it's possible and how it could be accomplished.
I am using rails 3.2. I am paginating my results using .page(1).per_page(10)
like
#users = User.method().page(1).per_page(10)
Now how to find the total count of the users from the pagination
As because #users.count gives 10 from the first page and not the total count
How to get the total count of the users even after pagination
EDIT : #users.total_count gives the whole paginated count
As mentioned in the question, you can get the total count of the records with
#users.total_count
I've added this as an answer for the sake of completeness.
You can use #users.total_count.
However, if you're trying to get the total count for each page, i.e. something like:
20 of 135 results
then total_count will just return 135, not the number of results on the page.
If you want to handle this case as well as the case where the number of results is less than the pagination result number, then I'd go with something like this:
(per_size > #users.total_count) ? #users.total_count : per_size
where per_size is the value you are setting for your per scope (docs here).
User.count would give you the count but it would hit the db. If you are using mongodb #user.length would give you the total count