# Multiple inner objects

**URL:** <https://discuss.elastic.co/t/multiple-inner-objects/2920>\
**Category:** Elasticsearch\
**Created:** [April 19, 2010, 11:16am UTC](https://discuss.elastic.co/t/multiple-inner-objects/2920 "2010-04-19T11:16:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bart\_Schuller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bart_schuller/32/3338_2.png) [@Bart\_Schuller](https://discuss.elastic.co/u/Bart_Schuller)\
**Post date:** [April 19, 2010, 11:16am UTC](https://discuss.elastic.co/t/multiple-inner-objects/2920/1 "2010-04-19T11:16:11Z")

</div>

Hello,

We are evaluating Lucene and in particular Elastic Search to see whether we can replace our existing search engine. One feature it has, which we use, is that it understands hierarchy in content. ElasticSearch has the beginning of similar support, but it looks like it's lacking a way to express certain queries.

An example says more than a thousand words. Below I add two documents representing families and their cars. Neither family owns a gray Toyota, yet both families are returned. The query is missing the constraint that car.make and car.color aren't independent, but should refer to the same car. In the other product, the query would look like:

```
(((Toyota <IN> make) <AND> (gray <IN> color)) <IN> car)

```

Would it be possible to add a similar feature to ElasticSearch?

I'm not aware that it's ever been done in a Lucene-based product. This mail to the Solr mailinglist shows how you could index the data such that it becomes possible to query the hierarchy, but care is needed because it uses a concatenation of two fields into one.

Thanks for a very exciting product and thanks or listening,

Regards,

Bart Schuller.

Here's the example as three shell statements:

curl -XPUT '[http://localhost:9200/zonetest/family/1](http://localhost:9200/zonetest/family/1)' -d '  
{  
"name": "Jones",  
"car": [  
{  
"make": "Toyota",  
"color": "green"  
},  
{  
"make": "Ford",  
"color": "gray"  
}  
]  
}  
'

curl -XPUT '[http://localhost:9200/zonetest/family/2](http://localhost:9200/zonetest/family/2)' -d '  
{  
"name": "Gates",  
"car": [  
{  
"make": "Rolls-Royce",  
"color": "gray"  
},  
{  
"make": "Toyota",  
"color": "blue"  
}  
]  
}  
'

curl -XGET '[http://localhost:9200/zonetest/family/\_search](http://localhost:9200/zonetest/family/_search)' -d '  
{  
"query" : {  
"bool" : {  
"must" : [  
{  
"field" : { "car.make" : "Toyota" }  
},  
{  
"field" : { "car.color" : "gray" }  
}  
]  
}  
}  
}  
'

--  
[Bart.Schuller@gmail.com](mailto:Bart.Schuller@gmail.com)

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [April 19, 2010, 11:43am UTC](https://discuss.elastic.co/t/multiple-inner-objects/2920/2 "2010-04-19T11:43:48Z")

</div>

Hiya

> An example says more than a thousand words. Below I add two documents  
> representing families and their cars. Neither family owns a gray  
> Toyota, yet both families are returned. The query is missing the  
> constraint that car.make and car.color aren't independent, but should  
> refer to the same car. In the other product, the query would look  
> like:
> 
> (((Toyota make) (gray color)) car)

Here's an example a search that looks for the words 'foo bar' in  
families that own toyotas with colours: red, blue, or gray:

curl -XGET '[http://127.0.0.2:9200/zonetest/family/\_search?search\_type=dfs\_query\_then\_fetch](http://127.0.0.2:9200/zonetest/family/_search?search_type=dfs_query_then_fetch)' -d '  
{  
"query" : {  
"filtered" : {  
"filter" : {  
"bool" : {  
"must" : [  
{  
"term" : {  
"car.make" : "toyota"  
}  
},  
{  
"terms" : {  
"car.color" : [  
"red",  
"blue",  
"gray"  
]  
}  
}  
]  
}  
},  
"query" : {  
"query\_string" : {  
"query" : "foo bar"  
}  
}  
}  
}  
}  
'

---

<div class="post-metadata">

**Author:** ![Bart\_Schuller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bart_schuller/32/3338_2.png) [@Bart\_Schuller](https://discuss.elastic.co/u/Bart_Schuller)\
**Post date:** [April 19, 2010, 12:19pm UTC](https://discuss.elastic.co/t/multiple-inner-objects/2920/3 "2010-04-19T12:19:54Z")

</div>

On Apr 19, 2010, at 13:43, Clinton Gormley wrote:

> Here's an example a search that looks for the words 'foo bar' in  
> families that own toyotas with colours: red, blue, or gray:

Well actually, it searches for 'foo bar' in families that own at least one Toyota and that own a car in either of those three colors. What I'm trying to express is that it's the Toyota that should be gray, not just any car like the Rolls.

It's something that would be expressed as a relation (join) if we were using SQL.

> curl -XGET '[http://127.0.0.2:9200/zonetest/family/\_search?search\_type=dfs\_query\_then\_fetch](http://127.0.0.2:9200/zonetest/family/_search?search_type=dfs_query_then_fetch)' -d '  
> {  
> "query" : {  
> "filtered" : {  
> "filter" : {  
> "bool" : {  
> "must" : [  
> {  
> "term" : {  
> "car.make" : "toyota"  
> }  
> },  
> {  
> "terms" : {  
> "car.color" : [  
> "red",  
> "blue",  
> "gray"  
> ]  
> }  
> }  
> ]  
> }  
> },  
> "query" : {  
> "query\_string" : {  
> "query" : "foo bar"  
> }  
> }  
> }  
> }  
> }  
> '

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [April 19, 2010, 12:31pm UTC](https://discuss.elastic.co/t/multiple-inner-objects/2920/4 "2010-04-19T12:31:40Z")

</div>

> Well actually, it searches for 'foo bar' in families that own at least  
> one Toyota and that own a car in either of those three colors. What  
> I'm trying to express is that it's the Toyota that should be gray, not  
> just any car like the Rolls.

True (and I didn't see your final query that demonstrated the same thing  
as I did 🙂

I'm not sure, but I think that currently you'd have to have add a field  
in order to achieve this, eg car.make\_color

---

<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:** [April 19, 2010, 3:13pm UTC](https://discuss.elastic.co/t/multiple-inner-objects/2920/5 "2010-04-19T15:13:55Z")

</div>

Yes, this is not currently possible (easily) with elasticsearch (or other  
Lucene based solution) though I do have some ideas (not fully formalized  
yet) on how to solve something like this. I hope to work on it soon....

cheers,  
shay.banon

On Mon, Apr 19, 2010 at 3:31 PM, Clinton Gormley [clinton@iannounce.co.uk](mailto:clinton@iannounce.co.uk)wrote:

> > Well actually, it searches for 'foo bar' in families that own at least  
> > one Toyota and that own a car in either of those three colors. What  
> > I'm trying to express is that it's the Toyota that should be gray, not  
> > just any car like the Rolls.
> 
> True (and I didn't see your final query that demonstrated the same thing  
> as I did 🙂
> 
> I'm not sure, but I think that currently you'd have to have add a field  
> in order to achieve this, eg car.make\_color

---

<div class="post-metadata">

**Author:** ![Leo1](https://avatars.discourse-cdn.com/v4/letter/l/85f322/32.png) [@Leo1](https://discuss.elastic.co/u/Leo1)\
**Post date:** [March 11, 2011, 8:00pm UTC](https://discuss.elastic.co/t/multiple-inner-objects/2920/6 "2011-03-11T20:00:15Z")

</div>

We are hoping to use this feature as well. I am wondering if there is any progress on this subject or how can we add this feature to elasticsearch. Thanks.

---

<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:10am UTC](https://discuss.elastic.co/t/multiple-inner-objects/2920/7 "2017-07-06T04:10:15Z")

</div>


