# Filter/match/return nested objects

**URL:** <https://discuss.elastic.co/t/filter-match-return-nested-objects/14622>\
**Category:** Elasticsearch\
**Created:** [November 27, 2013, 10:16pm UTC](https://discuss.elastic.co/t/filter-match-return-nested-objects/14622 "2013-11-27T22:16:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dionysis\_Lorentzos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dionysis_lorentzos/32/1711_2.png) [@Dionysis\_Lorentzos](https://discuss.elastic.co/u/Dionysis_Lorentzos)\
**Post date:** [November 27, 2013, 10:16pm UTC](https://discuss.elastic.co/t/filter-match-return-nested-objects/14622/1 "2013-11-27T22:16:54Z")

</div>

Hi all,

I have a question on ES use.

We assume that in our schema we have a user that has many posts. We want to  
search if the title or the description of a user's post contains a word and  
return those posts.  
Is it something doable with ES?

My try is:

{  
"query" : {  
"nested" : {  
"path" : "posts",  
"query" : {  
"multi\_match" : {  
"query" :'foo',  
"fields" : ["posts.title", "posts.description"]  
}  
}  
}  
}  
}

However the above returns the whole user document (/object) once the  
multi\_match criteria are true and not filtering each post in posts. I tried  
the same with nested as filter but I not much of a difference.

Thanks,  
D

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/028bd42a-3bb8-4c16-ade9-1d1f5b32259e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/028bd42a-3bb8-4c16-ade9-1d1f5b32259e%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 27, 2013, 10:20pm UTC](https://discuss.elastic.co/t/filter-match-return-nested-objects/14622/2 "2013-11-27T22:20:59Z")

</div>

My first thought about it is that if you are searching for posts then index posts!  
A posts can contain many attributes such as the user who wrote the post.

{  
"content" :"my text here",  
"user": {  
"login": "mylogin",  
"twitter":"myaccount"  
}  
}

What do you think? Could it help you to design your documents?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 27 novembre 2013 at 23:16:57, Dionysis Lorentzos ([ddl449@gmail.com](mailto:ddl449@gmail.com)) a écrit:

Hi all,

I have a question on ES use.

We assume that in our schema we have a user that has many posts. We want to search if the title or the description of a user's post contains a word and return those posts.  
Is it something doable with ES?

My try is:

{  
"query" : {  
"nested" : {  
"path" : "posts",  
"query" : {  
"multi\_match" : {  
"query" :'foo',  
"fields" : ["posts.title", "posts.description"]  
}  
}  
}  
}  
}

However the above returns the whole user document (/object) once the multi\_match criteria are true and not filtering each post in posts. I tried the same with nested as filter but I not much of a difference.

## Thanks, D

You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/028bd42a-3bb8-4c16-ade9-1d1f5b32259e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/028bd42a-3bb8-4c16-ade9-1d1f5b32259e%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/etPan.5296704b.2901d82.3e14%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5296704b.2901d82.3e14%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [November 27, 2013, 10:33pm UTC](https://discuss.elastic.co/t/filter-match-return-nested-objects/14622/3 "2013-11-27T22:33:25Z")

</div>

If I understand your issue correctlu, that feature is not yet supported:

> <https://github.com/elastic/elasticsearch/issues/3022>
>
> Add support for including the matching nested inner objects per hit element.

Cheers,

Ivan

On Wed, Nov 27, 2013 at 2:20 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> My first thought about it is that if you are searching for posts then  
> index posts!  
> A posts can contain many attributes such as the user who wrote the post.
> 
> {  
> "content" :"my text here",  
> "user": {  
> "login": "mylogin",  
> "twitter":"myaccount"  
> }  
> }
> 
> What do you think? Could it help you to design your documents?
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> 
> Le 27 novembre 2013 at 23:16:57, Dionysis Lorentzos ([ddl449@gmail.com](mailto:ddl449@gmail.com)//ddl449@gmail.com)  
> a écrit:
> 
> Hi all,
> 
> I have a question on ES use.
> 
> We assume that in our schema we have a user that has many posts. We want  
> to search if the title or the description of a user's post contains a word  
> and return those posts.  
> Is it something doable with ES?
> 
> My try is:
> 
> {  
> "query" : {  
> "nested" : {  
> "path" : "posts",  
> "query" : {  
> "multi\_match" : {  
> "query" :'foo',  
> "fields" : ["posts.title", "posts.description"]  
> }  
> }  
> }  
> }  
> }
> 
> However the above returns the whole user document (/object) once the  
> multi\_match criteria are true and not filtering each post in posts. I tried  
> the same with nested as filter but I not much of a difference.
> 
> ## Thanks, D
> 
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/028bd42a-3bb8-4c16-ade9-1d1f5b32259e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/028bd42a-3bb8-4c16-ade9-1d1f5b32259e%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/etPan.5296704b.2901d82.3e14%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5296704b.2901d82.3e14%40MacBook-Air-de-David.local)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQAegiaSOLGMsrzuJT9omhSR1HD1G-sjzRgx-\_72CKfuRQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQAegiaSOLGMsrzuJT9omhSR1HD1G-sjzRgx-_72CKfuRQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Dionysis\_Lorentzos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dionysis_lorentzos/32/1711_2.png) [@Dionysis\_Lorentzos](https://discuss.elastic.co/u/Dionysis_Lorentzos)\
**Post date:** [November 27, 2013, 10:49pm UTC](https://discuss.elastic.co/t/filter-match-return-nested-objects/14622/4 "2013-11-27T22:49:30Z")

</div>

Hi David and Ivan,

Well my data source is a MongoDB using Richard's river plugin[1].

So afaik, since I have a mongo collection of users it's not possible to  
index nested fields, or is it?

In practice I have:  
[http://localhost:9200/database/users/\_mapping/](http://localhost:9200/database/users/_mapping/) which gives:

{  
user : {  
name: {  
type: "string"  
},  
posts : {  
type: "nested",  
properties: {  
title: {  
type: "string"  
},  
description: {  
type: "string"  
}  
}  
}  
}  
}

but this cannot be done:

[http://localhost:9200/database/users/posts/\_mapping](http://localhost:9200/database/users/posts/_mapping)

as I get "No handler found for uri".

I think as Ivan posted, is not yet supported unless there is a workaround.  
Best,  
D

[1] [GitHub - richardwilly98/elasticsearch-river-mongodb: MongoDB River Plugin for ElasticSearch](https://github.com/richardwilly98/elasticsearch-river-mongodb)

On Thursday, November 28, 2013 12:33:25 AM UTC+2, Ivan Brusic wrote:

> If I understand your issue correctlu, that feature is not yet supported:  
> [Return matching nested inner objects per hit · Issue #3022 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/3022)
> 
> Cheers,
> 
> Ivan
> 
> On Wed, Nov 27, 2013 at 2:20 PM, David Pilato \<[da...@pilato.fr](mailto:da...@pilato.fr)\<javascript:\>
> 
> > wrote:
> 
> > My first thought about it is that if you are searching for posts then  
> > index posts!  
> > A posts can contain many attributes such as the user who wrote the post.
> > 
> > {  
> > "content" :"my text here",  
> > "user": {  
> > "login": "mylogin",  
> > "twitter":"myaccount"  
> > }  
> > }
> > 
> > What do you think? Could it help you to design your documents?
> > 
> > --  
> > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> > 
> > Le 27 novembre 2013 at 23:16:57, Dionysis Lorentzos ([ddl...@gmail.com](mailto:ddl...@gmail.com)\<javascript:\>)  
> > a écrit:
> > 
> > Hi all,
> > 
> > I have a question on ES use.
> > 
> > We assume that in our schema we have a user that has many posts. We want  
> > to search if the title or the description of a user's post contains a word  
> > and return those posts.  
> > Is it something doable with ES?
> > 
> > My try is:
> > 
> > {  
> > "query" : {  
> > "nested" : {  
> > "path" : "posts",  
> > "query" : {  
> > "multi\_match" : {  
> > "query" :'foo',  
> > "fields" : ["posts.title", "posts.description"]  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > However the above returns the whole user document (/object) once the  
> > multi\_match criteria are true and not filtering each post in posts. I tried  
> > the same with nested as filter but I not much of a difference.
> > 
> > ## Thanks, D
> > 
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/028bd42a-3bb8-4c16-ade9-1d1f5b32259e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/028bd42a-3bb8-4c16-ade9-1d1f5b32259e%40googlegroups.com)  
> > .  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/etPan.5296704b.2901d82.3e14%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5296704b.2901d82.3e14%40MacBook-Air-de-David.local)  
> > .
> > 
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0424de6e-b050-4461-a3f8-286d4299bbe0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0424de6e-b050-4461-a3f8-286d4299bbe0%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:04am UTC](https://discuss.elastic.co/t/filter-match-return-nested-objects/14622/5 "2017-07-06T02:04:24Z")

</div>


