# An Interesting Search Problem

**URL:** <https://discuss.elastic.co/t/an-interesting-search-problem/3252>\
**Category:** Elasticsearch\
**Created:** [August 24, 2010, 6:25pm UTC](https://discuss.elastic.co/t/an-interesting-search-problem/3252 "2010-08-24T18:25:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Jensen\_2](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@David\_Jensen\_2](https://discuss.elastic.co/u/David_Jensen_2)\
**Post date:** [August 24, 2010, 6:25pm UTC](https://discuss.elastic.co/t/an-interesting-search-problem/3252/1 "2010-08-24T18:25:05Z")

</div>

The follow example is a search problem that I'm trying to solve. This  
is example is more of an analogy but it should get the point across.

I have a master index of different beer selections. It has fields like  
the name of the beer, "Torpedo Extra IPA," the brewery, "Sierra  
Nevada," the abv, the color, the style, an official description, and  
more. Some breweries will change the details of some of these beers  
from year to year so this information would preferably live in only  
one index.

Next, each user has their own index of beer. In this index the user  
may include different details for each of beer fields. Most notably  
would be description. The user will very likely have their own  
specific notes for description.

Let's take the Torpedo Extra IPA example. The master index has the  
following document,

{  
\_id: 1980,  
name: "Torpedo Extra IPA",  
brewery: "Sierra Nevada",  
style: "IPA",  
description: "Sierra Nevada Torpedo Ale is a big American IPA;  
bold, assertive and full of flavor and aromas highlighting the complex  
citrus, pine and herbal character of whole-cone American hops."  
}

Let's say the user document is as follows ...

{  
\_id: 1980,  
description: "Hoppy, floral orange notes with a malty character  
balanced by a sharp spicy bitter hop bite. Contains Citra hops."  
}

The easiest way to describe how I want the results is likely the wrong  
way of thinking about the problem, but it's very clear to understand.  
I would like to basically search on description, joining on \_id,  
showing the data from the master record in the results. But it's a  
little more complicated than that. I actually want the "joined"  
results to appear first (let's say on average there are 5-10 of  
these), results only in the user index next, followed by results from  
only the master index.

I've thought of a few different way of doing this but I'd like to hear  
some other hopefully better ideas. I'm also willing to listen to  
"you're making it too complicated do this instead."

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [August 27, 2010, 11:51am UTC](https://discuss.elastic.co/t/an-interesting-search-problem/3252/2 "2010-08-27T11:51:04Z")

</div>

Hi,

If I got it correctly, it sounds like you will need to execute two  
queries (one against the user index, and one against the master index), and  
do the joining on the client side. Note that you might need to duplicate the  
master information on each user index if you want to match on that.

Another option is to create a single index, with "user" field for a  
document, the master will be a special "_master_" user. Then, you do a  
single search, and get back the relevant results back. You can filter the  
query with one that only matches on "_master_" and the user in question.

-shay.banon

On Tue, Aug 24, 2010 at 9:25 PM, David Jensen [djensen47@gmail.com](mailto:djensen47@gmail.com) wrote:

> The follow example is a search problem that I'm trying to solve. This  
> is example is more of an analogy but it should get the point across.
> 
> I have a master index of different beer selections. It has fields like  
> the name of the beer, "Torpedo Extra IPA," the brewery, "Sierra  
> Nevada," the abv, the color, the style, an official description, and  
> more. Some breweries will change the details of some of these beers  
> from year to year so this information would preferably live in only  
> one index.
> 
> Next, each user has their own index of beer. In this index the user  
> may include different details for each of beer fields. Most notably  
> would be description. The user will very likely have their own  
> specific notes for description.
> 
> Let's take the Torpedo Extra IPA example. The master index has the  
> following document,
> 
> {  
> \_id: 1980,  
> name: "Torpedo Extra IPA",  
> brewery: "Sierra Nevada",  
> style: "IPA",  
> description: "Sierra Nevada Torpedo Ale is a big American IPA;  
> bold, assertive and full of flavor and aromas highlighting the complex  
> citrus, pine and herbal character of whole-cone American hops."  
> }
> 
> Let's say the user document is as follows ...
> 
> {  
> \_id: 1980,  
> description: "Hoppy, floral orange notes with a malty character  
> balanced by a sharp spicy bitter hop bite. Contains Citra hops."  
> }
> 
> The easiest way to describe how I want the results is likely the wrong  
> way of thinking about the problem, but it's very clear to understand.  
> I would like to basically search on description, joining on \_id,  
> showing the data from the master record in the results. But it's a  
> little more complicated than that. I actually want the "joined"  
> results to appear first (let's say on average there are 5-10 of  
> these), results only in the user index next, followed by results from  
> only the master index.
> 
> I've thought of a few different way of doing this but I'd like to hear  
> some other hopefully better ideas. I'm also willing to listen to  
> "you're making it too complicated do this instead."

---

<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, 4:20am UTC](https://discuss.elastic.co/t/an-interesting-search-problem/3252/3 "2017-07-06T04:20:15Z")

</div>

Closed on July 6, 2017, 4:20am UTC


