# Use case advice

**URL:** https://discuss.elastic.co/t/use-case-advice/7176
**Category:** Elasticsearch
**Created:** [March 30, 2012, 10:54am UTC](https://discuss.elastic.co/t/use-case-advice/7176 "2012-03-30T10:54:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Santiago\_Basulto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/santiago_basulto/32/2810_2.png) [@Santiago\_Basulto](https://discuss.elastic.co/u/Santiago_Basulto)
#### Post date: [March 30, 2012, 10:54am UTC](https://discuss.elastic.co/t/use-case-advice/7176/1 "2012-03-30T10:54:16Z")

</div>

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](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](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](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!

---

<div class="post-metadata">

### Author: ![Michael\_Sick](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@Michael\_Sick](https://discuss.elastic.co/u/Michael_Sick)
#### Post date: [March 30, 2012, 2:55pm UTC](https://discuss.elastic.co/t/use-case-advice/7176/2 "2012-03-30T14:55:45Z")

</div>

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](http://www.elasticsearch.org/guide/reference/mapping/boost-field.html) for  
per field boosting and/or Index Boosting:  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://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:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Finally  
to match on partials you might be able to get away with using Prefix:  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/prefix-query.html) or  
you might want to consider a non default analyzers / tokenizers:  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/)

--Mike

On Fri, Mar 30, 2012 at 6:54 AM, Santiago Basulto \<  
[santiago.basulto@gmail.com](mailto: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](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](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](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!

---

<div class="post-metadata">

### Author: ![Santiago\_Basulto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/santiago_basulto/32/2810_2.png) [@Santiago\_Basulto](https://discuss.elastic.co/u/Santiago_Basulto)
#### Post date: [March 30, 2012, 3:13pm UTC](https://discuss.elastic.co/t/use-case-advice/7176/3 "2012-03-30T15:13:26Z")

</div>

Thank you for your answer Mike!

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

> <https://gist.github.com/santiagobasulto/2252157>

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](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:  
> [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/reference/mapping/boost-field.html) for  
> per field boosting and/or Index Boosting:  
> [Elastic — The Search AI Company | Elastic](http://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:  
> [Elastic — The Search AI Company | Elastic](http://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:  
> [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/prefix-query.html) or  
> you might want to consider a non default analyzers / tokenizers:  
> [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/)
> 
> --Mike

---

<div class="post-metadata">

### Author: ![Michael\_Sick](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@Michael\_Sick](https://discuss.elastic.co/u/Michael_Sick)
#### Post date: [April 4, 2012, 5:37pm UTC](https://discuss.elastic.co/t/use-case-advice/7176/4 "2012-04-04T17:37:33Z")

</div>

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

On Fri, Mar 30, 2012 at 11:13 AM, Santiago Basulto \<  
[santiago.basulto@gmail.com](mailto: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](https://gist.github.com/2252157)
> 
> 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](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/](http://www.elasticsearch.org/)\*\*  
> > guide/reference/mapping/boost-**field.html[http://www.elasticsearch.org/guide/reference/mapping/boost-field.html](http://www.elasticsearch.org/guide/reference/mapping/boost-field.html) for  
> > per field boosting and/or Index Boosting: [http://www](http://www).**  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/guide/ **reference/api/search/index-** boost.html)[http://www.elasticsearch.org/guide/reference/api/search/index-boost.html](http://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](http://www).\*\*[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/guide/)  
> > \*\*reference/mapping/multi-field-\*\*type.html[http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html](http://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](http://www).\*\*[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/guide/) **reference/query-dsl/prefix-**  
> > query.html[http://www.elasticsearch.org/guide/reference/query-dsl/prefix-query.html](http://www.elasticsearch.org/guide/reference/query-dsl/prefix-query.html) or  
> > you might want to consider a non default analyzers / tokenizers:  
> > [http://www](http://www).\*\*[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/guide/) **reference/index-modules/**  
> > analysis/[http://www.elasticsearch.org/guide/reference/index-modules/analysis/](http://www.elasticsearch.org/guide/reference/index-modules/analysis/)
> > 
> > --Mike

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 6, 2017, 3:33am UTC](https://discuss.elastic.co/t/use-case-advice/7176/5 "2017-07-06T03:33:36Z")

</div>


