# Nested documents search

**URL:** <https://discuss.elastic.co/t/nested-documents-search/13185>\
**Category:** Elasticsearch\
**Created:** [August 12, 2013, 9:05pm UTC](https://discuss.elastic.co/t/nested-documents-search/13185 "2013-08-12T21:05:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhishek\_Andhavarapu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abhishek_andhavarapu/32/782_2.png) [@Abhishek\_Andhavarapu](https://discuss.elastic.co/u/Abhishek_Andhavarapu)\
**Post date:** [August 12, 2013, 9:05pm UTC](https://discuss.elastic.co/t/nested-documents-search/13185/1 "2013-08-12T21:05:16Z")

</div>

All,

I have nested documents with the following structure

rtext :  
{  
id : integer,  
value : string  
}

rdata  
{  
id : integer.  
value : float  
}

I'm trying to search all the documents with id = 1 and value = xxx

{  
"filter": {  
"nested": {  
"path": "rtext",  
"query": {  
"bool": {  
"must": [  
{  
"term": {  
"rtext.textmapid": "1"  
}  
},  
{  
"term": {  
"rtext.textvalue": "xxx"  
}  
}  
]  
}  
}  
}  
}  
}

The query returns 0 results. But If the ran the same rdata which has value  
type as float it comes back with results. Am I missing anything ?

Thanks,  
Abhishek

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 13, 2013, 6:54am UTC](https://discuss.elastic.co/t/nested-documents-search/13185/2 "2013-08-13T06:54:18Z")

</div>

Hey,

can you maybe provide a full minimal example including mapping, indexing  
data and full queries. This would allow other people to reproduce your  
issue easily and see what is wrong. Also including the case where  
everything works, would be useful.

Thanks!

--Alex

On Mon, Aug 12, 2013 at 11:05 PM, Abhishek Andhavarapu \<  
[abhishek376@gmail.com](mailto:abhishek376@gmail.com)\> wrote:

> All,
> 
> I have nested documents with the following structure
> 
> rtext :  
> {  
> id : integer,  
> value : string  
> }
> 
> rdata  
> {  
> id : integer.  
> value : float  
> }
> 
> I'm trying to search all the documents with id = 1 and value = xxx
> 
> {  
> "filter": {  
> "nested": {  
> "path": "rtext",  
> "query": {  
> "bool": {  
> "must": [  
> {  
> "term": {  
> "rtext.textmapid": "1"  
> }  
> },  
> {  
> "term": {  
> "rtext.textvalue": "xxx"  
> }  
> }  
> ]  
> }  
> }  
> }  
> }  
> }
> 
> The query returns 0 results. But If the ran the same rdata which has value  
> type as float it comes back with results. Am I missing anything ?
> 
> Thanks,  
> Abhishek
> 
> --  
> 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).  
> 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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Abhishek\_Andhavarapu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abhishek_andhavarapu/32/782_2.png) [@Abhishek\_Andhavarapu](https://discuss.elastic.co/u/Abhishek_Andhavarapu)\
**Post date:** [August 13, 2013, 9:04pm UTC](https://discuss.elastic.co/t/nested-documents-search/13185/3 "2013-08-13T21:04:38Z")

</div>

Alex,

Thanks for the reply.

My Mappings  
{  
"response": {  
"properties": {  
"rtext": {  
"type": "nested",  
"properties": {  
"textmapid": {  
"type": "integer"  
},  
"textvalue": {  
"type": "string"  
}  
}  
}  
}  
}  
}

Sample data

{  
"rtext" : [  
{  
"textmapid" : 1,  
"textvalue" : "Jennifer"  
},  
{  
"textmapid" : 2,  
"textvalue" : "Adam"  
}  
]  
}

My query

Term filter does not work.

{  
"filter": {  
"nested": {  
"path": "rtext",  
"query": {  
"bool": {  
"must": [  
{  
"term": {  
"rtext.textvalue": "Jennifer"  
}  
},  
{  
"term": {  
"rtext.textmapid": 1  
}  
}  
]  
}  
}  
}  
}  
}

Match filter works  
{  
"filter": {  
"nested": {  
"path": "rtext",  
"query": {  
"bool": {  
"must": [  
{  
"match": {  
"rtext.textvalue": "Jennifer"  
}  
},  
{  
"term": {  
"rtext.textmapid": 1  
}  
}  
]  
}  
}  
}  
}  
}

Prefix filter doesn't work but match\_phrase\_prefix works.

1)Term filter doesn't work but match filter works why ?  
2) Prefix filter doesn't work but match\_phrase\_prefix works. What the  
difference between match and match\_phrase ?  
3) How do I write a begins with and ends with filter ? I tried regex filter  
with "Jen._" and \bJen(._)\b for begins with it didnot work ?  
4) How do I write a exists and missing filter they dont work either.

{  
"filter": {  
"nested": {  
"path": "rtext",  
"query": {  
"bool": {  
"must": [  
{  
"exists": {  
"field": "rtext.textvalue"  
}  
},  
{  
"term": {  
"rtext.textmapid": 1  
}  
}  
]  
}  
}  
}  
}  
}

Thanks,  
Abhishek

On Tue, Aug 13, 2013 at 12:54 AM, Alexander Reelsen [alr@spinscale.de](mailto:alr@spinscale.de)wrote:

> Hey,
> 
> can you maybe provide a full minimal example including mapping, indexing  
> data and full queries. This would allow other people to reproduce your  
> issue easily and see what is wrong. Also including the case where  
> everything works, would be useful.
> 
> Thanks!
> 
> --Alex
> 
> On Mon, Aug 12, 2013 at 11:05 PM, Abhishek Andhavarapu \<  
> [abhishek376@gmail.com](mailto:abhishek376@gmail.com)\> wrote:
> 
> > All,
> > 
> > I have nested documents with the following structure
> > 
> > rtext :  
> > {  
> > id : integer,  
> > value : string  
> > }
> > 
> > rdata  
> > {  
> > id : integer.  
> > value : float  
> > }
> > 
> > I'm trying to search all the documents with id = 1 and value = xxx
> > 
> > {  
> > "filter": {  
> > "nested": {  
> > "path": "rtext",  
> > "query": {  
> > "bool": {  
> > "must": [  
> > {  
> > "term": {  
> > "rtext.textmapid": "1"  
> > }  
> > },  
> > {  
> > "term": {  
> > "rtext.textvalue": "xxx"  
> > }  
> > }  
> > ]  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > The query returns 0 results. But If the ran the same rdata which has  
> > value type as float it comes back with results. Am I missing anything ?
> > 
> > Thanks,  
> > Abhishek
> > 
> > --  
> > 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).
> > 
> > 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 a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/zIqeV\_yjG2A/unsubscribe](https://groups.google.com/d/topic/elasticsearch/zIqeV_yjG2A/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [August 16, 2013, 9:15pm UTC](https://discuss.elastic.co/t/nested-documents-search/13185/4 "2013-08-16T21:15:39Z")

</div>

1)Term filter doesn't work but match filter works why ?

Because term filter doesn't analyze the search string and match filter  
does. There is not token "Jennifer" in your index, only "jennifer".

1. Prefix filter doesn't work but match\_phrase\_prefix works. What the  
difference between match and match\_phrase ?

See 1)

1. How do I write a begins with and ends with filter ? I tried regex filter  
with "Jen._" and \bJen(._)\b for begins with it didnot work ?

You might be better using EdgeNGrams here, but at least lowercase your term.

1. How do I write a exists and missing filter they dont work either.

exists is a filter (not query) so it should be:

{  
"filter": {  
"nested": {  
"path": "rtext",

- 

```
 "filter": {*
  "bool": {
    "must": [
      {
        "exists": {
          "field": "rtext.textvalue"
        }
      },
      {
        "term": {
          "rtext.textmapid": 1
        }
      }
    ]
  }
}

```

}  
}  
}

On Tuesday, August 13, 2013 5:04:38 PM UTC-4, Abhishek Andhavarapu wrote:

> Alex,
> 
> Thanks for the reply.
> 
> My Mappings  
> {  
> "response": {  
> "properties": {  
> "rtext": {  
> "type": "nested",  
> "properties": {  
> "textmapid": {  
> "type": "integer"  
> },  
> "textvalue": {  
> "type": "string"  
> }  
> }  
> }  
> }  
> }  
> }
> 
> Sample data
> 
> {  
> "rtext" : [  
> {  
> "textmapid" : 1,  
> "textvalue" : "Jennifer"  
> },  
> {  
> "textmapid" : 2,  
> "textvalue" : "Adam"  
> }  
> ]  
> }
> 
> My query
> 
> Term filter does not work.
> 
> {  
> "filter": {  
> "nested": {  
> "path": "rtext",  
> "query": {  
> "bool": {  
> "must": [  
> {  
> "term": {  
> "rtext.textvalue": "Jennifer"  
> }  
> },  
> {  
> "term": {  
> "rtext.textmapid": 1  
> }  
> }  
> ]  
> }  
> }  
> }  
> }  
> }
> 
> Match filter works  
> {  
> "filter": {  
> "nested": {  
> "path": "rtext",  
> "query": {  
> "bool": {  
> "must": [  
> {  
> "match": {  
> "rtext.textvalue": "Jennifer"  
> }  
> },  
> {  
> "term": {  
> "rtext.textmapid": 1  
> }  
> }  
> ]  
> }  
> }  
> }  
> }  
> }
> 
> Prefix filter doesn't work but match\_phrase\_prefix works.
> 
> 1)Term filter doesn't work but match filter works why ?  
> 2) Prefix filter doesn't work but match\_phrase\_prefix works. What the  
> difference between match and match\_phrase ?  
> 3) How do I write a begins with and ends with filter ? I tried regex  
> filter with "Jen._" and \bJen(._)\b for begins with it didnot work ?  
> 4) How do I write a exists and missing filter they dont work either.
> 
> {  
> "filter": {  
> "nested": {  
> "path": "rtext",  
> "query": {  
> "bool": {  
> "must": [  
> {  
> "exists": {  
> "field": "rtext.textvalue"  
> }  
> },  
> {  
> "term": {  
> "rtext.textmapid": 1  
> }  
> }  
> ]  
> }  
> }  
> }  
> }  
> }
> 
> Thanks,  
> Abhishek
> 
> On Tue, Aug 13, 2013 at 12:54 AM, Alexander Reelsen \<[a...@spinscale.de](mailto:a...@spinscale.de)\<javascript:\>
> 
> > wrote:
> 
> > Hey,
> > 
> > can you maybe provide a full minimal example including mapping, indexing  
> > data and full queries. This would allow other people to reproduce your  
> > issue easily and see what is wrong. Also including the case where  
> > everything works, would be useful.
> > 
> > Thanks!
> > 
> > --Alex
> > 
> > On Mon, Aug 12, 2013 at 11:05 PM, Abhishek Andhavarapu \<  
> > [abhis...@gmail.com](mailto:abhis...@gmail.com) \<javascript:\>\> wrote:
> > 
> > > All,
> > > 
> > > I have nested documents with the following structure
> > > 
> > > rtext :  
> > > {  
> > > id : integer,  
> > > value : string  
> > > }
> > > 
> > > rdata  
> > > {  
> > > id : integer.  
> > > value : float  
> > > }
> > > 
> > > I'm trying to search all the documents with id = 1 and value = xxx
> > > 
> > > {  
> > > "filter": {  
> > > "nested": {  
> > > "path": "rtext",  
> > > "query": {  
> > > "bool": {  
> > > "must": [  
> > > {  
> > > "term": {  
> > > "rtext.textmapid": "1"  
> > > }  
> > > },  
> > > {  
> > > "term": {  
> > > "rtext.textvalue": "xxx"  
> > > }  
> > > }  
> > > ]  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > The query returns 0 results. But If the ran the same rdata which has  
> > > value type as float it comes back with results. Am I missing anything ?
> > > 
> > > Thanks,  
> > > Abhishek
> > > 
> > > --  
> > > 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:\>.
> > > 
> > > 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 a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/zIqeV\_yjG2A/unsubscribe](https://groups.google.com/d/topic/elasticsearch/zIqeV_yjG2A/unsubscribe).  
> > To unsubscribe from this group and all its topics, send an email to  
> > [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > 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).  
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:20am UTC](https://discuss.elastic.co/t/nested-documents-search/13185/5 "2017-07-06T02:20:48Z")

</div>


