Sort the basic of Number of documents

I am saving user relations in ES Index

i.e

{'id' => 1, 'User_id_1' => '2001', 'relation' => 'friend', 'User_id_2' =>
'1002'}
{'id' => 2, 'User_id_1' => '2002', 'relation' => 'friend', 'User_id_2' =>
'1002'}

{'id' => 3, 'User_id_1' => '2002', 'relation' => 'friend', 'User_id_2' =>
'1001'}
{'id' => 4, 'User_id_1' => '2003', 'relation' => 'friend', 'User_id_2' =>
'1003'}

no suppose i want to get the user_id_2 who has most friends,

in above case its 1002 as 2001, and 2002 are its friends. (Count = 2)

I just can't figure out the query

Thanks.

--

What about TermFacet on field user_id_2?

--

Le 11 août 2012 à 14:39, Chetan Sharma carl@izap.in a écrit :

I am saving user relations in ES Index

i.e

{'id' => 1, 'User_id_1' => '2001', 'relation' => 'friend', 'User_id_2' => '1002'}
{'id' => 2, 'User_id_1' => '2002', 'relation' => 'friend', 'User_id_2' => '1002'}

{'id' => 3, 'User_id_1' => '2002', 'relation' => 'friend', 'User_id_2' => '1001'}
{'id' => 4, 'User_id_1' => '2003', 'relation' => 'friend', 'User_id_2' => '1003'}

no suppose i want to get the user_id_2 who has most friends,

in above case its 1002 as 2001, and 2002 are its friends. (Count = 2)

I just can't figure out the query

Thanks.

--

--

I am trying that, thanks 4 idea will post back the results soon.
-----Original Message-----
From: David Pilato david@pilato.fr
Sender: elasticsearch@googlegroups.com
Date: Sat, 11 Aug 2012 14:58:55
To: elasticsearch@googlegroups.comelasticsearch@googlegroups.com
Reply-To: elasticsearch@googlegroups.com
Subject: Re: Sort the basic of Number of documents

What about TermFacet on field user_id_2?

--

Le 11 août 2012 à 14:39, Chetan Sharma carl@izap.in a écrit :

I am saving user relations in ES Index

i.e

{'id' => 1, 'User_id_1' => '2001', 'relation' => 'friend', 'User_id_2' => '1002'}
{'id' => 2, 'User_id_1' => '2002', 'relation' => 'friend', 'User_id_2' => '1002'}

{'id' => 3, 'User_id_1' => '2002', 'relation' => 'friend', 'User_id_2' => '1001'}
{'id' => 4, 'User_id_1' => '2003', 'relation' => 'friend', 'User_id_2' => '1003'}

no suppose i want to get the user_id_2 who has most friends,

in above case its 1002 as 2001, and 2002 are its friends. (Count = 2)

I just can't figure out the query

Thanks.

--

--

--

Well "term facets" is very good choice and it almost solved my problem, but

The problem is I have is 2 Indexes

1st index is for saving the main docs and 2nd index for saving the relations

now problem is

Suppose I have 100 USER Docs in my main index, only 50 of them has made
relations, so I'll have only 50 USER Docs in my relationship index

So when i implement the "term facet", it sorts the results and gives the
correct output i want, but I am missing those left 50 users who don't have
any relations yet, i need them in my final output after the 50 sorted users.

On Saturday, August 11, 2012 6:28:55 PM UTC+5:30, David Pilato wrote:

What about TermFacet on field user_id_2?

--

Le 11 août 2012 à 14:39, Chetan Sharma <ca...@izap.in <javascript:>> a
écrit :

I am saving user relations in ES Index

i.e

{'id' => 1, 'User_id_1' => '2001', 'relation' => 'friend', 'User_id_2' =>
'1002'}
{'id' => 2, 'User_id_1' => '2002', 'relation' => 'friend', 'User_id_2' =>
'1002'}

{'id' => 3, 'User_id_1' => '2002', 'relation' => 'friend', 'User_id_2' =>
'1001'}
{'id' => 4, 'User_id_1' => '2003', 'relation' => 'friend', 'User_id_2' =>
'1003'}

no suppose i want to get the user_id_2 who has most friends,

in above case its 1002 as 2001, and 2002 are its friends. (Count = 2)

I just can't figure out the query

Thanks.

--

--

What I would do for your use case is to think my documents in another way.

I mean that you want to store users. Users have relations. So store relations as a field of your user document.

Then it will be easier to query for users or relations.

If you need to filter by number of relations, why not adding a numberofrelation property in your user doc?

David

--

Le 13 août 2012 à 09:37, Chetan Sharma carl@izap.in a écrit :

Well "term facets" is very good choice and it almost solved my problem, but

The problem is I have is 2 Indexes

1st index is for saving the main docs and 2nd index for saving the relations

now problem is

Suppose I have 100 USER Docs in my main index, only 50 of them has made relations, so I'll have only 50 USER Docs in my relationship index

So when i implement the "term facet", it sorts the results and gives the correct output i want, but I am missing those left 50 users who don't have any relations yet, i need them in my final output after the 50 sorted users.

On Saturday, August 11, 2012 6:28:55 PM UTC+5:30, David Pilato wrote:
What about TermFacet on field user_id_2?

--

Le 11 août 2012 à 14:39, Chetan Sharma ca...@izap.in a écrit :

I am saving user relations in ES Index

i.e

{'id' => 1, 'User_id_1' => '2001', 'relation' => 'friend', 'User_id_2' => '1002'}
{'id' => 2, 'User_id_1' => '2002', 'relation' => 'friend', 'User_id_2' => '1002'}

{'id' => 3, 'User_id_1' => '2002', 'relation' => 'friend', 'User_id_2' => '1001'}
{'id' => 4, 'User_id_1' => '2003', 'relation' => 'friend', 'User_id_2' => '1003'}

no suppose i want to get the user_id_2 who has most friends,

in above case its 1002 as 2001, and 2002 are its friends. (Count = 2)

I just can't figure out the query

Thanks.

--

--

--

If we add relations to the same DOC, the Document will increase to very
large size.

Suppose I save

friend_of : [array of ids],
fan_of : [array of ids]

if user have 10,000 fans and 1000 friends, then the size of document will
be very large

So it modular to keep it in different index.

On Mon, Aug 13, 2012 at 1:16 PM, David Pilato david@pilato.fr wrote:

What I would do for your use case is to think my documents in another way.

I mean that you want to store users. Users have relations. So store
relations as a field of your user document.

Then it will be easier to query for users or relations.

If you need to filter by number of relations, why not adding a
numberofrelation property in your user doc?

David

--

Le 13 août 2012 à 09:37, Chetan Sharma carl@izap.in a écrit :

Well "term facets" is very good choice and it almost solved my problem, but

The problem is I have is 2 Indexes

1st index is for saving the main docs and 2nd index for saving the
relations

now problem is

Suppose I have 100 USER Docs in my main index, only 50 of them has made
relations, so I'll have only 50 USER Docs in my relationship index

So when i implement the "term facet", it sorts the results and gives the
correct output i want, but I am missing those left 50 users who don't have
any relations yet, i need them in my final output after the 50 sorted users.

On Saturday, August 11, 2012 6:28:55 PM UTC+5:30, David Pilato wrote:

What about TermFacet on field user_id_2?

--

Le 11 août 2012 à 14:39, Chetan Sharma ca...@izap.in a écrit :

I am saving user relations in ES Index

i.e

{'id' => 1, 'User_id_1' => '2001', 'relation' => 'friend', 'User_id_2' =>
'1002'}
{'id' => 2, 'User_id_1' => '2002', 'relation' => 'friend', 'User_id_2' =>
'1002'}

{'id' => 3, 'User_id_1' => '2002', 'relation' => 'friend', 'User_id_2' =>
'1001'}
{'id' => 4, 'User_id_1' => '2003', 'relation' => 'friend', 'User_id_2' =>
'1003'}

no suppose i want to get the user_id_2 who has most friends,

in above case its 1002 as 2001, and 2002 are its friends. (Count = 2)

I just can't figure out the query

Thanks.

--

--

--

--

Chetan Sharma
iZAP

--

I see. But my last comment can do the job. "adding a numberofrelation property in your user doc?"

--

Le 13 août 2012 à 09:53, Chetan Sharma chetan@izap.in a écrit :

If we add relations to the same DOC, the Document will increase to very large size.

Suppose I save

friend_of : [array of ids],
fan_of : [array of ids]

if user have 10,000 fans and 1000 friends, then the size of document will be very large

So it modular to keep it in different index.

On Mon, Aug 13, 2012 at 1:16 PM, David Pilato david@pilato.fr wrote:
What I would do for your use case is to think my documents in another way.

I mean that you want to store users. Users have relations. So store relations as a field of your user document.

Then it will be easier to query for users or relations.

If you need to filter by number of relations, why not adding a numberofrelation property in your user doc?

David

--

Le 13 août 2012 à 09:37, Chetan Sharma carl@izap.in a écrit :

Well "term facets" is very good choice and it almost solved my problem, but

The problem is I have is 2 Indexes

1st index is for saving the main docs and 2nd index for saving the relations

now problem is

Suppose I have 100 USER Docs in my main index, only 50 of them has made relations, so I'll have only 50 USER Docs in my relationship index

So when i implement the "term facet", it sorts the results and gives the correct output i want, but I am missing those left 50 users who don't have any relations yet, i need them in my final output after the 50 sorted users.

On Saturday, August 11, 2012 6:28:55 PM UTC+5:30, David Pilato wrote:
What about TermFacet on field user_id_2?

--

Le 11 août 2012 à 14:39, Chetan Sharma ca...@izap.in a écrit :

I am saving user relations in ES Index

i.e

{'id' => 1, 'User_id_1' => '2001', 'relation' => 'friend', 'User_id_2' => '1002'}
{'id' => 2, 'User_id_1' => '2002', 'relation' => 'friend', 'User_id_2' => '1002'}

{'id' => 3, 'User_id_1' => '2002', 'relation' => 'friend', 'User_id_2' => '1001'}
{'id' => 4, 'User_id_1' => '2003', 'relation' => 'friend', 'User_id_2' => '1003'}

no suppose i want to get the user_id_2 who has most friends,

in above case its 1002 as 2001, and 2002 are its friends. (Count = 2)

I just can't figure out the query

Thanks.

--

--

--

--

Chetan Sharma
iZAP

--

--

Yes you are right, but according to our current conventions (Project
management), we are not allowed to keep the "COUNTERS".

Isn't there any solution around this in Elasticsearch Queries ?

On Mon, Aug 13, 2012 at 1:26 PM, David Pilato david@pilato.fr wrote:

I see. But my last comment can do the job. "adding a numberofrelation
property in your user doc?"

--

Le 13 août 2012 à 09:53, Chetan Sharma chetan@izap.in a écrit :

If we add relations to the same DOC, the Document will increase to very
large size.

Suppose I save

friend_of : [array of ids],
fan_of : [array of ids]

if user have 10,000 fans and 1000 friends, then the size of document will
be very large

So it modular to keep it in different index.

On Mon, Aug 13, 2012 at 1:16 PM, David Pilato david@pilato.fr wrote:

What I would do for your use case is to think my documents in another way.

I mean that you want to store users. Users have relations. So store
relations as a field of your user document.

Then it will be easier to query for users or relations.

If you need to filter by number of relations, why not adding a
numberofrelation property in your user doc?

David

--

Le 13 août 2012 à 09:37, Chetan Sharma carl@izap.in a écrit :

Well "term facets" is very good choice and it almost solved my problem,
but

The problem is I have is 2 Indexes

1st index is for saving the main docs and 2nd index for saving the
relations

now problem is

Suppose I have 100 USER Docs in my main index, only 50 of them has made
relations, so I'll have only 50 USER Docs in my relationship index

So when i implement the "term facet", it sorts the results and gives the
correct output i want, but I am missing those left 50 users who don't have
any relations yet, i need them in my final output after the 50 sorted users.

On Saturday, August 11, 2012 6:28:55 PM UTC+5:30, David Pilato wrote:

What about TermFacet on field user_id_2?

--

Le 11 août 2012 à 14:39, Chetan Sharma ca...@izap.in a écrit :

I am saving user relations in ES Index

i.e

{'id' => 1, 'User_id_1' => '2001', 'relation' => 'friend', 'User_id_2'
=> '1002'}
{'id' => 2, 'User_id_1' => '2002', 'relation' => 'friend', 'User_id_2'
=> '1002'}

{'id' => 3, 'User_id_1' => '2002', 'relation' => 'friend', 'User_id_2'
=> '1001'}
{'id' => 4, 'User_id_1' => '2003', 'relation' => 'friend', 'User_id_2'
=> '1003'}

no suppose i want to get the user_id_2 who has most friends,

in above case its 1002 as 2001, and 2002 are its friends. (Count = 2)

I just can't figure out the query

Thanks.

--

--

--

--

Chetan Sharma
iZAP

--

--

--

Chetan Sharma
iZAP

--