Use case advice

Hello guys,

first let me apologize for my english, I'm from Argentina. I've to say i
don't have lots of experience with ES, so forgive me if say something wrong.

Here's my problem.

I'm building something similar to a social networking site. I've got users
and friendships between users. Something really similar to facebook. At the
top of the page, each user see a search bar where he/her can search for
people there (again, similar to FB).

I've followed this great tutorial by Clinton:
http://elasticsearch-users.115913.n3.nabble.com/help-needed-with-the-query-tt3177477.html#a3178856 And
i've got something working right now. Actually I've got a pretty good
results with that looking for users.

The problem is that when a user search in that search bar I'd like to
search first for his/her friends, and after that i'd like to get regular
users. I mean, if the user types "Rob" i'd like to get something like:

Rob Smith (Friend)
Robert Bonham (a friend too)
Rob Jones (Not a friend)
Roberta Mendez (Not a friend).

Plain simple: It should be sorted by friendship (first appear the friends
of the user).

What i got now is a type with a mapping for the "user" type, where i have
all my users. The problem is how to structure my types and mapping in order
to sort by this "friendship" condition.

The only thing i can think now is having a mapping for each user containing
it's friends, something like:

(supposing the user seraching ID is 1000)

http://host:9200/mySocialNetwork/friend/1000/_search?name=Rob

I could search for that first and after that intersect that result with
this:

http://host:9200/mySocialNetwork/user/_search?name=Rob

But, that doesn't seem really well, I think must be some better way to do
this.

Can you help me?

Thank you a lot!

Santiago,

I think your solution will cover a couple of topics. You'll wan to look
into:

Score Boosting:
Elasticsearch Platform — Find real-time answers at scale | Elastic for
per field boosting and/or Index Boosting:
Elasticsearch Platform — Find real-time answers at scale | Elastic if
Friends vs. People are in different indices.

You might want to map a single field into multiple views that differ by the
way that they're indexed using:

Finally
to match on partials you might be able to get away with using Prefix:
Elasticsearch Platform — Find real-time answers at scale | Elastic or
you might want to consider a non default analyzers / tokenizers:
Elasticsearch Platform — Find real-time answers at scale | Elastic

--Mike

On Fri, Mar 30, 2012 at 6:54 AM, Santiago Basulto <
santiago.basulto@gmail.com> wrote:

Hello guys,

first let me apologize for my english, I'm from Argentina. I've to say i
don't have lots of experience with ES, so forgive me if say something wrong.

Here's my problem.

I'm building something similar to a social networking site. I've got users
and friendships between users. Something really similar to facebook. At the
top of the page, each user see a search bar where he/her can search for
people there (again, similar to FB).

I've followed this great tutorial by Clinton:
http://elasticsearch-users.115913.n3.nabble.com/help-needed-with-the-query-tt3177477.html#a3178856 And
i've got something working right now. Actually I've got a pretty good
results with that looking for users.

The problem is that when a user search in that search bar I'd like to
search first for his/her friends, and after that i'd like to get regular
users. I mean, if the user types "Rob" i'd like to get something like:

Rob Smith (Friend)
Robert Bonham (a friend too)
Rob Jones (Not a friend)
Roberta Mendez (Not a friend).

Plain simple: It should be sorted by friendship (first appear the friends
of the user).

What i got now is a type with a mapping for the "user" type, where i have
all my users. The problem is how to structure my types and mapping in order
to sort by this "friendship" condition.

The only thing i can think now is having a mapping for each user
containing it's friends, something like:

(supposing the user seraching ID is 1000)

http://host:9200/mySocialNetwork/friend/1000/_search?name=Rob

I could search for that first and after that intersect that result with
this:

http://host:9200/mySocialNetwork/user/_search?name=Rob

But, that doesn't seem really well, I think must be some better way to do
this.

Can you help me?

Thank you a lot!

Thank you for your answer Mike!

Right now i've the user type, defined with this mapping:

I've been taking a look at the index-bost stuff you sent me, that could
work. Maybe if i define a new type (eg: friend)similar to the user and just
search for:

Searchig for rob

curl -XGET 'http://127.0.0.1:9200/user,friend/_search?pretty=1' -d '{
"query" : {
bool:
{ should: [
{ text: { "first_name": "rob" }},
{ text: { "first_name.partial": "rob" }}
]
}
}
}'

I think that should work.

I've just some question:

  1. I assume the results will be repited (i mean, finding a user on the
    friend index will show the same entry on the user index), how can i filter
    it?
  2. What's the correct boost level, i think i could just do:

{
"indices_boost" : {
"friends" : 2,
"users" : 1
}
}

Thank you again Mike!

El viernes 30 de marzo de 2012 11:55:45 UTC-3, Michael Sick escribió:

Santiago,

I think your solution will cover a couple of topics. You'll wan to look
into:

Score Boosting:
Elasticsearch Platform — Find real-time answers at scale | Elastic for
per field boosting and/or Index Boosting:
Elasticsearch Platform — Find real-time answers at scale | Elastic if
Friends vs. People are in different indices.

You might want to map a single field into multiple views that differ by
the way that they're indexed using:
Elasticsearch Platform — Find real-time answers at scale | Elastic Finally
to match on partials you might be able to get away with using Prefix:
Elasticsearch Platform — Find real-time answers at scale | Elastic or
you might want to consider a non default analyzers / tokenizers:
Elasticsearch Platform — Find real-time answers at scale | Elastic

--Mike

Sorry for the lag Santiago - didn't catch this.

On Fri, Mar 30, 2012 at 11:13 AM, Santiago Basulto <
santiago.basulto@gmail.com> wrote:

Thank you for your answer Mike!

Right now i've the user type, defined with this mapping:

User Mapping · GitHub

I've been taking a look at the index-bost stuff you sent me, that could
work. Maybe if i define a new type (eg: friend)similar to the user and just
search for:

Searchig for rob

curl -XGET 'http://127.0.0.1:9200/user,friend/_search?pretty=1' -d '{
"query" : {
bool:
{ should: [
{ text: { "first_name": "rob" }},
{ text: { "first_name.partial": "rob" }}
]
}
}
}'

I think that should work.

I've just some question:

  1. I assume the results will be repited (i mean, finding a user on the
    friend index will show the same entry on the user index), how can i filter
    it?

I'd have to think that through. This is for simple suggestion type
feedback? If so and since you wont have to deal with paging and more
detailed results - then ordering and then hand filtering by user id should
do it.

  1. What's the correct boost level, i think i could just do:

I believe it's all relative so that looks fine.

{

"indices_boost" : {

    "friends" : 2,

    "users" : 1

}

}

Thank you again Mike!

El viernes 30 de marzo de 2012 11:55:45 UTC-3, Michael Sick escribió:

Santiago,

I think your solution will cover a couple of topics. You'll wan to look
into:

Score Boosting: http://www.elasticsearch.org/**
guide/reference/mapping/boost-field.htmlhttp://www.elasticsearch.org/guide/reference/mapping/boost-field.html for
per field boosting and/or Index Boosting: http://www.

Elasticsearch Platform — Find real-time answers at scale | Elastichttp://www.elasticsearch.org/guide/reference/api/search/index-boost.html if
Friends vs. People are in different indices.

You might want to map a single field into multiple views that differ by
the way that they're indexed using: http://www.**Elasticsearch Platform — Find real-time answers at scale | Elastic
**reference/mapping/multi-field-**type.htmlhttp://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html Finally
to match on partials you might be able to get away with using Prefix:
http://www.**Elasticsearch Platform — Find real-time answers at scale | Elasticreference/query-dsl/prefix-
query.htmlhttp://www.elasticsearch.org/guide/reference/query-dsl/prefix-query.html or
you might want to consider a non default analyzers / tokenizers:
http://www.**Elasticsearch Platform — Find real-time answers at scale | Elasticreference/index-modules/
analysis/http://www.elasticsearch.org/guide/reference/index-modules/analysis/

--Mike