# Can't find anything with nested queries with 0.17.1

**URL:** <https://discuss.elastic.co/t/cant-find-anything-with-nested-queries-with-0-17-1/4938>\
**Category:** Elasticsearch\
**Created:** [July 24, 2011, 2:56pm UTC](https://discuss.elastic.co/t/cant-find-anything-with-nested-queries-with-0-17-1/4938 "2011-07-24T14:56:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_Pilone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dan_pilone/32/3261_2.png) [@Dan\_Pilone](https://discuss.elastic.co/u/Dan_Pilone)\
**Post date:** [July 24, 2011, 2:56pm UTC](https://discuss.elastic.co/t/cant-find-anything-with-nested-queries-with-0-17-1/4938/1 "2011-07-24T14:56:12Z")

</div>

All,  
I'm stuck. We have an index of approx 100M documents with lots of  
parent/child relationships. Some of our parent/child queries are  
extremely slow so we wanted to look at the new nested object/query  
capabilities in 0.17.1. We tried converting one of our parent/child  
relationships over but couldn't ever find results. Figuring we just  
had something wrong with our query generation I started putting  
together a really simple example but I can't get that working either.  
Can someone please help?

First, I started with a completely new elastic 0.17.1 install.  
Next, create an index as follows:

curl -XPUT [http://localhost:9200/echo](http://localhost:9200/echo) -d '{ "settings" : { "index" :  
{ "number\_of\_shards" : 3 } } }'

Then I loaded a simple mapping:

curl -XPUT [http://localhost:9200/echo/dataset/\_mapping](http://localhost:9200/echo/dataset/_mapping) -d '  
{  
"dataset": {  
"properties": {  
"provider\_id":{"type":"string","index":"not\_analyzed"},  
"inner\_thing" : {  
"type" : "nested",  
"properties" : {  
"first\_name" : { "type" : "string", "index" :  
"not\_analyzed"},  
"last\_name" : { "type" : "string", "index" :  
"not\_analyzed"}  
}  
}  
}  
}  
}'

Then index a document:

curl -XPOST [http://localhost:9200/\_bulk](http://localhost:9200/_bulk) -d '  
{"index":{"\_index":"echo","\_type":"dataset","\_id":"C1000000000-  
PROV2"}}  
{"provider\_id":"PROV2", "inner\_thing.first\_name" : "Dan",  
"inner\_thing.last\_name" : "Pilone"}  
'

Finally, try to find it:

curl -XGET [http://localhost:9200/echo/dataset/\_search?pretty=true](http://localhost:9200/echo/dataset/_search?pretty=true) -d '  
{  
"query" : {  
"filtered" : {  
"query" : { "match\_all" : {} },  
"filter" : {  
"nested" : {  
"path" : "inner\_thing",  
"query" : {  
"bool" : {  
"must" : [  
{"text" : { "inner\_thing.first\_name" :  
"Dan" }},  
{"text" : { "inner\_thing.last\_name" :  
"Pilone"}}  
]  
}  
}  
}  
}  
}  
}  
}  
'

I even tried a simpler one:

curl -XGET [http://localhost:9200/echo/dataset/\_search?pretty=true](http://localhost:9200/echo/dataset/_search?pretty=true) -d '  
{  
"query" : {  
"filtered" : {  
"query" : { "match\_all" : {} },  
"filter" : {  
"nested" : {  
"path" : "inner\_thing",  
"query" : {  
"bool" : {  
"must" : {  
"text" : { "first\_name" : "Dan" }  
}  
}  
}  
}  
}  
}  
}  
}  
'

If I drop the conditions, this works:

curl -XGET [http://localhost:9200/echo/dataset/\_search?pretty=true](http://localhost:9200/echo/dataset/_search?pretty=true) -d '  
{  
"query" : { "match\_all" : {} }  
}  
'

I'm stuck.... what am I missing? Thanks -- Dan

---

<div class="post-metadata">

**Author:** ![Dan\_Pilone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dan_pilone/32/3261_2.png) [@Dan\_Pilone](https://discuss.elastic.co/u/Dan_Pilone)\
**Post date:** [July 24, 2011, 3:12pm UTC](https://discuss.elastic.co/t/cant-find-anything-with-nested-queries-with-0-17-1/4938/2 "2011-07-24T15:12:26Z")

</div>

Sigh - ok, not two seconds after posting that I realized where I  
messed up in creating the inner object. You should index the document  
like this:

curl -XPOST [http://localhost:9200/\_bulk](http://localhost:9200/_bulk) -d '{"index":  
{"\_index":"echo","\_type":"dataset","\_id":"C1000000000-PROV2"}}  
{"provider\_id":"PROV2", "inner\_thing" :{ "first\_name" : "Dan",  
"inner\_thing.last\_name" : "Pilone"}}  
'

That makes this search work as expected:

curl -XGET [http://localhost:9200/echo/dataset/\_search?pretty=true](http://localhost:9200/echo/dataset/_search?pretty=true) -d  
'  
{  
"query" : {  
"filtered" : {  
"query" : { "match\_all" : {} },  
"filter" : {  
"nested" : {  
"path" : "inner\_thing",  
"query" : {  
"bool" : {  
"must" : {  
"text" : { "first\_name" : "Dan" }  
}  
}  
}  
}  
}  
}  
}  
}

'

But still doesn't get this one working:  
curl -XGET [http://localhost:9200/echo/dataset/\_search?pretty=true](http://localhost:9200/echo/dataset/_search?pretty=true) -d  
'  
{  
"query" : {  
"filtered" : {  
"query" : { "match\_all" : {} },  
"filter" : {  
"nested" : {  
"path" : "inner\_thing",  
"query" : {  
"bool" : {  
"must" : [  
{"text" : { "inner\_thing.first\_name" :  
"Dan" }},  
{"text" : { "inner\_thing.last\_name" :  
"Pilone"}}  
]  
}  
}  
}  
}  
}  
}  
}

'

Still digging... -- Dan

On Jul 24, 10:56 am, Dan Pilone [d...@element84.com](mailto:d...@element84.com) wrote:

> All,  
> I'm stuck. We have an index of approx 100M documents with lots of  
> parent/child relationships. Some of our parent/child queries are  
> extremely slow so we wanted to look at the new nested object/query  
> capabilities in 0.17.1. We tried converting one of our parent/child  
> relationships over but couldn't ever find results. Figuring we just  
> had something wrong with our query generation I started putting  
> together a really simple example but I can't get that working either.  
> Can someone please help?
> 
> First, I started with a completely new elastic 0.17.1 install.  
> Next, create an index as follows:
> 
> curl -XPUThttp://localhost:9200/echo-d '{ "settings" : { "index" :  
> { "number\_of\_shards" : 3 } } }'
> 
> Then I loaded a simple mapping:
> 
> curl -XPUThttp://localhost:9200/echo/dataset/\_mapping-d '  
> {  
> "dataset": {  
> "properties": {  
> "provider\_id":{"type":"string","index":"not\_analyzed"},  
> "inner\_thing" : {  
> "type" : "nested",  
> "properties" : {  
> "first\_name" : { "type" : "string", "index" :  
> "not\_analyzed"},  
> "last\_name" : { "type" : "string", "index" :  
> "not\_analyzed"}  
> }  
> }  
> }  
> }
> 
> }'
> 
> Then index a document:
> 
> curl -XPOSThttp://localhost:9200/\_bulk-d '  
> {"index":{"\_index":"echo","\_type":"dataset","\_id":"C1000000000-  
> PROV2"}}  
> {"provider\_id":"PROV2", "inner\_thing.first\_name" : "Dan",  
> "inner\_thing.last\_name" : "Pilone"}  
> '
> 
> Finally, try to find it:
> 
> curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d '  
> {  
> "query" : {  
> "filtered" : {  
> "query" : { "match\_all" : {} },  
> "filter" : {  
> "nested" : {  
> "path" : "inner\_thing",  
> "query" : {  
> "bool" : {  
> "must" : [  
> {"text" : { "inner\_thing.first\_name" :  
> "Dan" }},  
> {"text" : { "inner\_thing.last\_name" :  
> "Pilone"}}  
> ]  
> }  
> }  
> }  
> }  
> }  
> }}
> 
> '
> 
> I even tried a simpler one:
> 
> curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d '  
> {  
> "query" : {  
> "filtered" : {  
> "query" : { "match\_all" : {} },  
> "filter" : {  
> "nested" : {  
> "path" : "inner\_thing",  
> "query" : {  
> "bool" : {  
> "must" : {  
> "text" : { "first\_name" : "Dan" }  
> }  
> }  
> }  
> }  
> }  
> }  
> }}
> 
> '
> 
> If I drop the conditions, this works:
> 
> curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d '  
> {  
> "query" : { "match\_all" : {} }}
> 
> '
> 
> I'm stuck.... what am I missing? Thanks -- Dan

---

<div class="post-metadata">

**Author:** ![Dan\_Pilone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dan_pilone/32/3261_2.png) [@Dan\_Pilone](https://discuss.elastic.co/u/Dan_Pilone)\
**Post date:** [July 24, 2011, 3:14pm UTC](https://discuss.elastic.co/t/cant-find-anything-with-nested-queries-with-0-17-1/4938/3 "2011-07-24T15:14:46Z")

</div>

Ok, apparently the secret to solving any problem is to post it  
somewhere public where you can prove you don't know what you're  
doing. Another typo in my indexing. Now both queries work as  
expected:

curl -XPOST [http://localhost:9200/\_bulk](http://localhost:9200/_bulk) -d '{"index":  
{"\_index":"echo","\_type":"dataset","\_id":"C1000000000-PROV2"}}  
{"provider\_id":"PROV2", "inner\_thing" :{ "first\_name" : "Dan",  
"last\_name" : "Pilone"}}  
'

Now both queries work and find that document. On to testing multiple  
"inner\_thing"s. Thanks for listening. -- Dan

On Jul 24, 11:12 am, Dan Pilone [d...@element84.com](mailto:d...@element84.com) wrote:

> Sigh - ok, not two seconds after posting that I realized where I  
> messed up in creating the inner object. You should index the document  
> like this:
> 
> curl -XPOSThttp://localhost:9200/\_bulk-d '{"index":  
> {"\_index":"echo","\_type":"dataset","\_id":"C1000000000-PROV2"}}  
> {"provider\_id":"PROV2", "inner\_thing" :{ "first\_name" : "Dan",  
> "inner\_thing.last\_name" : "Pilone"}}  
> '
> 
> That makes this search work as expected:
> 
> curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d  
> '  
> {  
> "query" : {  
> "filtered" : {  
> "query" : { "match\_all" : {} },  
> "filter" : {  
> "nested" : {  
> "path" : "inner\_thing",  
> "query" : {  
> "bool" : {  
> "must" : {  
> "text" : { "first\_name" : "Dan" }  
> }  
> }  
> }  
> }  
> }  
> }  
> }
> 
> }
> 
> '
> 
> But still doesn't get this one working:  
> curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d  
> '  
> {  
> "query" : {  
> "filtered" : {  
> "query" : { "match\_all" : {} },  
> "filter" : {  
> "nested" : {  
> "path" : "inner\_thing",  
> "query" : {  
> "bool" : {  
> "must" : [  
> {"text" : { "inner\_thing.first\_name" :  
> "Dan" }},  
> {"text" : { "inner\_thing.last\_name" :  
> "Pilone"}}  
> ]  
> }  
> }  
> }  
> }  
> }  
> }
> 
> }
> 
> '
> 
> Still digging... -- Dan
> 
> On Jul 24, 10:56 am, Dan Pilone [d...@element84.com](mailto:d...@element84.com) wrote:
> 
> > All,  
> > I'm stuck. We have an index of approx 100M documents with lots of  
> > parent/child relationships. Some of our parent/child queries are  
> > extremely slow so we wanted to look at the new nested object/query  
> > capabilities in 0.17.1. We tried converting one of our parent/child  
> > relationships over but couldn't ever find results. Figuring we just  
> > had something wrong with our query generation I started putting  
> > together a really simple example but I can't get that working either.  
> > Can someone please help?
> 
> > First, I started with a completely new elastic 0.17.1 install.  
> > Next, create an index as follows:
> 
> > curl -XPUThttp://localhost:9200/echo-d'{ "settings" : { "index" :  
> > { "number\_of\_shards" : 3 } } }'
> 
> > Then I loaded a simple mapping:
> 
> > curl -XPUThttp://localhost:9200/echo/dataset/\_mapping-d'  
> > {  
> > "dataset": {  
> > "properties": {  
> > "provider\_id":{"type":"string","index":"not\_analyzed"},  
> > "inner\_thing" : {  
> > "type" : "nested",  
> > "properties" : {  
> > "first\_name" : { "type" : "string", "index" :  
> > "not\_analyzed"},  
> > "last\_name" : { "type" : "string", "index" :  
> > "not\_analyzed"}  
> > }  
> > }  
> > }  
> > }
> 
> > }'
> 
> > Then index a document:
> 
> > curl -XPOSThttp://localhost:9200/\_bulk-d'  
> > {"index":{"\_index":"echo","\_type":"dataset","\_id":"C1000000000-  
> > PROV2"}}  
> > {"provider\_id":"PROV2", "inner\_thing.first\_name" : "Dan",  
> > "inner\_thing.last\_name" : "Pilone"}  
> > '
> 
> > Finally, try to find it:
> 
> > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d'  
> > {  
> > "query" : {  
> > "filtered" : {  
> > "query" : { "match\_all" : {} },  
> > "filter" : {  
> > "nested" : {  
> > "path" : "inner\_thing",  
> > "query" : {  
> > "bool" : {  
> > "must" : [  
> > {"text" : { "inner\_thing.first\_name" :  
> > "Dan" }},  
> > {"text" : { "inner\_thing.last\_name" :  
> > "Pilone"}}  
> > ]  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }}
> 
> > '
> 
> > I even tried a simpler one:
> 
> > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d'  
> > {  
> > "query" : {  
> > "filtered" : {  
> > "query" : { "match\_all" : {} },  
> > "filter" : {  
> > "nested" : {  
> > "path" : "inner\_thing",  
> > "query" : {  
> > "bool" : {  
> > "must" : {  
> > "text" : { "first\_name" : "Dan" }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }}
> 
> > '
> 
> > If I drop the conditions, this works:
> 
> > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d'  
> > {  
> > "query" : { "match\_all" : {} }}
> 
> > '
> 
> > I'm stuck.... what am I missing? Thanks -- Dan

---

<div class="post-metadata">

**Author:** ![Nicolas\_Lalevee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolas_lalevee/32/2892_2.png) [@Nicolas\_Lalevee](https://discuss.elastic.co/u/Nicolas_Lalevee)\
**Post date:** [July 25, 2011, 9:13am UTC](https://discuss.elastic.co/t/cant-find-anything-with-nested-queries-with-0-17-1/4938/4 "2011-07-25T09:13:03Z")

</div>

Thank you Dan for your monologue, it helped me understand what nested documents and nested query actually are 🙂

If I can suggest improvement to the documentation, it would be great if it can state which "document" is actually returned by a nested query.

> **[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.

It doesn't really state that querying nested doc returned the "root" doc. Maybe obvious, but not that clear to me.

And in that page the links which references the nested mapping is broken.

Nicolas

Le 24 juil. 2011 à 17:14, Dan Pilone a écrit :

> Ok, apparently the secret to solving any problem is to post it  
> somewhere public where you can prove you don't know what you're  
> doing. Another typo in my indexing. Now both queries work as  
> expected:
> 
> curl -XPOST [http://localhost:9200/\_bulk](http://localhost:9200/_bulk) -d '{"index":  
> {"\_index":"echo","\_type":"dataset","\_id":"C1000000000-PROV2"}}  
> {"provider\_id":"PROV2", "inner\_thing" :{ "first\_name" : "Dan",  
> "last\_name" : "Pilone"}}  
> '
> 
> Now both queries work and find that document. On to testing multiple  
> "inner\_thing"s. Thanks for listening. -- Dan
> 
> On Jul 24, 11:12 am, Dan Pilone [d...@element84.com](mailto:d...@element84.com) wrote:
> 
> > Sigh - ok, not two seconds after posting that I realized where I  
> > messed up in creating the inner object. You should index the document  
> > like this:
> > 
> > curl -XPOSThttp://localhost:9200/\_bulk-d '{"index":  
> > {"\_index":"echo","\_type":"dataset","\_id":"C1000000000-PROV2"}}  
> > {"provider\_id":"PROV2", "inner\_thing" :{ "first\_name" : "Dan",  
> > "inner\_thing.last\_name" : "Pilone"}}  
> > '
> > 
> > That makes this search work as expected:
> > 
> > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d  
> > '  
> > {  
> > "query" : {  
> > "filtered" : {  
> > "query" : { "match\_all" : {} },  
> > "filter" : {  
> > "nested" : {  
> > "path" : "inner\_thing",  
> > "query" : {  
> > "bool" : {  
> > "must" : {  
> > "text" : { "first\_name" : "Dan" }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > }
> > 
> > '
> > 
> > But still doesn't get this one working:  
> > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d  
> > '  
> > {  
> > "query" : {  
> > "filtered" : {  
> > "query" : { "match\_all" : {} },  
> > "filter" : {  
> > "nested" : {  
> > "path" : "inner\_thing",  
> > "query" : {  
> > "bool" : {  
> > "must" : [  
> > {"text" : { "inner\_thing.first\_name" :  
> > "Dan" }},  
> > {"text" : { "inner\_thing.last\_name" :  
> > "Pilone"}}  
> > ]  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > }
> > 
> > '
> > 
> > Still digging... -- Dan
> > 
> > On Jul 24, 10:56 am, Dan Pilone [d...@element84.com](mailto:d...@element84.com) wrote:
> > 
> > > All,  
> > > I'm stuck. We have an index of approx 100M documents with lots of  
> > > parent/child relationships. Some of our parent/child queries are  
> > > extremely slow so we wanted to look at the new nested object/query  
> > > capabilities in 0.17.1. We tried converting one of our parent/child  
> > > relationships over but couldn't ever find results. Figuring we just  
> > > had something wrong with our query generation I started putting  
> > > together a really simple example but I can't get that working either.  
> > > Can someone please help?
> > 
> > > First, I started with a completely new elastic 0.17.1 install.  
> > > Next, create an index as follows:
> > 
> > > curl -XPUThttp://localhost:9200/echo-d'{ "settings" : { "index" :  
> > > { "number\_of\_shards" : 3 } } }'
> > 
> > > Then I loaded a simple mapping:
> > 
> > > curl -XPUThttp://localhost:9200/echo/dataset/\_mapping-d'  
> > > {  
> > > "dataset": {  
> > > "properties": {  
> > > "provider\_id":{"type":"string","index":"not\_analyzed"},  
> > > "inner\_thing" : {  
> > > "type" : "nested",  
> > > "properties" : {  
> > > "first\_name" : { "type" : "string", "index" :  
> > > "not\_analyzed"},  
> > > "last\_name" : { "type" : "string", "index" :  
> > > "not\_analyzed"}  
> > > }  
> > > }  
> > > }  
> > > }
> > 
> > > }'
> > 
> > > Then index a document:
> > 
> > > curl -XPOSThttp://localhost:9200/\_bulk-d'  
> > > {"index":{"\_index":"echo","\_type":"dataset","\_id":"C1000000000-  
> > > PROV2"}}  
> > > {"provider\_id":"PROV2", "inner\_thing.first\_name" : "Dan",  
> > > "inner\_thing.last\_name" : "Pilone"}  
> > > '
> > 
> > > Finally, try to find it:
> > 
> > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d'  
> > > {  
> > > "query" : {  
> > > "filtered" : {  
> > > "query" : { "match\_all" : {} },  
> > > "filter" : {  
> > > "nested" : {  
> > > "path" : "inner\_thing",  
> > > "query" : {  
> > > "bool" : {  
> > > "must" : [  
> > > {"text" : { "inner\_thing.first\_name" :  
> > > "Dan" }},  
> > > {"text" : { "inner\_thing.last\_name" :  
> > > "Pilone"}}  
> > > ]  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }}
> > 
> > > '
> > 
> > > I even tried a simpler one:
> > 
> > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d'  
> > > {  
> > > "query" : {  
> > > "filtered" : {  
> > > "query" : { "match\_all" : {} },  
> > > "filter" : {  
> > > "nested" : {  
> > > "path" : "inner\_thing",  
> > > "query" : {  
> > > "bool" : {  
> > > "must" : {  
> > > "text" : { "first\_name" : "Dan" }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }}
> > 
> > > '
> > 
> > > If I drop the conditions, this works:
> > 
> > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d'  
> > > {  
> > > "query" : { "match\_all" : {} }}
> > 
> > > '
> > 
> > > I'm stuck.... what am I missing? Thanks -- Dan

---

<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:** [July 25, 2011, 12:22pm UTC](https://discuss.elastic.co/t/cant-find-anything-with-nested-queries-with-0-17-1/4938/5 "2011-07-25T12:22:59Z")

</div>

2011/7/25 Nicolas Lalevée [nicolas.lalevee@hibnet.org](mailto:nicolas.lalevee@hibnet.org)

> Thank you Dan for your monologue, it helped me understand what nested  
> documents and nested query actually are 🙂
> 
> If I can suggest improvement to the documentation, it would be great if it  
> can state which "document" is actually returned by a nested query.  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html)  
> It doesn't really state that querying nested doc returned the "root" doc.  
> Maybe obvious, but not that clear to me.

Its stated there: "... resulting in the root parent doc (or parent nested  
mapping) ... ", right in the first para

> And in that page the links which references the nested mapping is broken.

Fixed.

> Nicolas
> 
> Le 24 juil. 2011 à 17:14, Dan Pilone a écrit :
> 
> > Ok, apparently the secret to solving any problem is to post it  
> > somewhere public where you can prove you don't know what you're  
> > doing. Another typo in my indexing. Now both queries work as  
> > expected:
> > 
> > curl -XPOST [http://localhost:9200/\_bulk](http://localhost:9200/_bulk) -d '{"index":  
> > {"\_index":"echo","\_type":"dataset","\_id":"C1000000000-PROV2"}}  
> > {"provider\_id":"PROV2", "inner\_thing" :{ "first\_name" : "Dan",  
> > "last\_name" : "Pilone"}}  
> > '
> > 
> > Now both queries work and find that document. On to testing multiple  
> > "inner\_thing"s. Thanks for listening. -- Dan
> > 
> > On Jul 24, 11:12 am, Dan Pilone [d...@element84.com](mailto:d...@element84.com) wrote:
> > 
> > > Sigh - ok, not two seconds after posting that I realized where I  
> > > messed up in creating the inner object. You should index the document  
> > > like this:
> > > 
> > > curl -XPOSThttp://localhost:9200/\_bulk-d '{"index":  
> > > {"\_index":"echo","\_type":"dataset","\_id":"C1000000000-PROV2"}}  
> > > {"provider\_id":"PROV2", "inner\_thing" :{ "first\_name" : "Dan",  
> > > "inner\_thing.last\_name" : "Pilone"}}  
> > > '
> > > 
> > > That makes this search work as expected:
> > > 
> > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d  
> > > '  
> > > {  
> > > "query" : {  
> > > "filtered" : {  
> > > "query" : { "match\_all" : {} },  
> > > "filter" : {  
> > > "nested" : {  
> > > "path" : "inner\_thing",  
> > > "query" : {  
> > > "bool" : {  
> > > "must" : {  
> > > "text" : { "first\_name" : "Dan" }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > }
> > > 
> > > '
> > > 
> > > But still doesn't get this one working:  
> > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d  
> > > '  
> > > {  
> > > "query" : {  
> > > "filtered" : {  
> > > "query" : { "match\_all" : {} },  
> > > "filter" : {  
> > > "nested" : {  
> > > "path" : "inner\_thing",  
> > > "query" : {  
> > > "bool" : {  
> > > "must" : [  
> > > {"text" : { "inner\_thing.first\_name" :  
> > > "Dan" }},  
> > > {"text" : { "inner\_thing.last\_name" :  
> > > "Pilone"}}  
> > > ]  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > }
> > > 
> > > '
> > > 
> > > Still digging... -- Dan
> > > 
> > > On Jul 24, 10:56 am, Dan Pilone [d...@element84.com](mailto:d...@element84.com) wrote:
> > > 
> > > > All,  
> > > > I'm stuck. We have an index of approx 100M documents with lots of  
> > > > parent/child relationships. Some of our parent/child queries are  
> > > > extremely slow so we wanted to look at the new nested object/query  
> > > > capabilities in 0.17.1. We tried converting one of our parent/child  
> > > > relationships over but couldn't ever find results. Figuring we just  
> > > > had something wrong with our query generation I started putting  
> > > > together a really simple example but I can't get that working either.  
> > > > Can someone please help?
> > > 
> > > > First, I started with a completely new elastic 0.17.1 install.  
> > > > Next, create an index as follows:
> > > 
> > > > curl -XPUThttp://localhost:9200/echo-d'{ "settings" : { "index" :  
> > > > { "number\_of\_shards" : 3 } } }'
> > > 
> > > > Then I loaded a simple mapping:
> > > 
> > > > curl -XPUThttp://localhost:9200/echo/dataset/\_mapping-d'  
> > > > {  
> > > > "dataset": {  
> > > > "properties": {  
> > > > "provider\_id":{"type":"string","index":"not\_analyzed"},  
> > > > "inner\_thing" : {  
> > > > "type" : "nested",  
> > > > "properties" : {  
> > > > "first\_name" : { "type" : "string", "index" :  
> > > > "not\_analyzed"},  
> > > > "last\_name" : { "type" : "string", "index" :  
> > > > "not\_analyzed"}  
> > > > }  
> > > > }  
> > > > }  
> > > > }
> > > 
> > > > }'
> > > 
> > > > Then index a document:
> > > 
> > > > curl -XPOSThttp://localhost:9200/\_bulk-d'  
> > > > {"index":{"\_index":"echo","\_type":"dataset","\_id":"C1000000000-  
> > > > PROV2"}}  
> > > > {"provider\_id":"PROV2", "inner\_thing.first\_name" : "Dan",  
> > > > "inner\_thing.last\_name" : "Pilone"}  
> > > > '
> > > 
> > > > Finally, try to find it:
> > > 
> > > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d'  
> > > > {  
> > > > "query" : {  
> > > > "filtered" : {  
> > > > "query" : { "match\_all" : {} },  
> > > > "filter" : {  
> > > > "nested" : {  
> > > > "path" : "inner\_thing",  
> > > > "query" : {  
> > > > "bool" : {  
> > > > "must" : [  
> > > > {"text" : { "inner\_thing.first\_name" :  
> > > > "Dan" }},  
> > > > {"text" : { "inner\_thing.last\_name" :  
> > > > "Pilone"}}  
> > > > ]  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }}
> > > 
> > > > '
> > > 
> > > > I even tried a simpler one:
> > > 
> > > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d'  
> > > > {  
> > > > "query" : {  
> > > > "filtered" : {  
> > > > "query" : { "match\_all" : {} },  
> > > > "filter" : {  
> > > > "nested" : {  
> > > > "path" : "inner\_thing",  
> > > > "query" : {  
> > > > "bool" : {  
> > > > "must" : {  
> > > > "text" : { "first\_name" : "Dan" }  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }}
> > > 
> > > > '
> > > 
> > > > If I drop the conditions, this works:
> > > 
> > > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d'  
> > > > {  
> > > > "query" : { "match\_all" : {} }}
> > > 
> > > > '
> > > 
> > > > I'm stuck.... what am I missing? Thanks -- Dan

---

<div class="post-metadata">

**Author:** ![Nicolas\_Lalevee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolas_lalevee/32/2892_2.png) [@Nicolas\_Lalevee](https://discuss.elastic.co/u/Nicolas_Lalevee)\
**Post date:** [July 25, 2011, 12:36pm UTC](https://discuss.elastic.co/t/cant-find-anything-with-nested-queries-with-0-17-1/4938/6 "2011-07-25T12:36:07Z")

</div>

Le 25 juil. 2011 à 14:22, Shay Banon a écrit :

> 2011/7/25 Nicolas Lalevée [nicolas.lalevee@hibnet.org](mailto:nicolas.lalevee@hibnet.org)  
> Thank you Dan for your monologue, it helped me understand what nested documents and nested query actually are 🙂
> 
> If I can suggest improvement to the documentation, it would be great if it can state which "document" is actually returned by a nested query.  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html)  
> It doesn't really state that querying nested doc returned the "root" doc. Maybe obvious, but not that clear to me.
> 
> Its stated there: "... resulting in the root parent doc (or parent nested mapping) ... ", right in the first para

........ shame on me......

> And in that page the links which references the nested mapping is broken.
> 
> Fixed.

thanks !

Nicolas

> Nicolas
> 
> Le 24 juil. 2011 à 17:14, Dan Pilone a écrit :
> 
> > Ok, apparently the secret to solving any problem is to post it  
> > somewhere public where you can prove you don't know what you're  
> > doing. Another typo in my indexing. Now both queries work as  
> > expected:
> > 
> > curl -XPOST [http://localhost:9200/\_bulk](http://localhost:9200/_bulk) -d '{"index":  
> > {"\_index":"echo","\_type":"dataset","\_id":"C1000000000-PROV2"}}  
> > {"provider\_id":"PROV2", "inner\_thing" :{ "first\_name" : "Dan",  
> > "last\_name" : "Pilone"}}  
> > '
> > 
> > Now both queries work and find that document. On to testing multiple  
> > "inner\_thing"s. Thanks for listening. -- Dan
> > 
> > On Jul 24, 11:12 am, Dan Pilone [d...@element84.com](mailto:d...@element84.com) wrote:
> > 
> > > Sigh - ok, not two seconds after posting that I realized where I  
> > > messed up in creating the inner object. You should index the document  
> > > like this:
> > > 
> > > curl -XPOSThttp://localhost:9200/\_bulk-d '{"index":  
> > > {"\_index":"echo","\_type":"dataset","\_id":"C1000000000-PROV2"}}  
> > > {"provider\_id":"PROV2", "inner\_thing" :{ "first\_name" : "Dan",  
> > > "inner\_thing.last\_name" : "Pilone"}}  
> > > '
> > > 
> > > That makes this search work as expected:
> > > 
> > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d  
> > > '  
> > > {  
> > > "query" : {  
> > > "filtered" : {  
> > > "query" : { "match\_all" : {} },  
> > > "filter" : {  
> > > "nested" : {  
> > > "path" : "inner\_thing",  
> > > "query" : {  
> > > "bool" : {  
> > > "must" : {  
> > > "text" : { "first\_name" : "Dan" }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > }
> > > 
> > > '
> > > 
> > > But still doesn't get this one working:  
> > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d  
> > > '  
> > > {  
> > > "query" : {  
> > > "filtered" : {  
> > > "query" : { "match\_all" : {} },  
> > > "filter" : {  
> > > "nested" : {  
> > > "path" : "inner\_thing",  
> > > "query" : {  
> > > "bool" : {  
> > > "must" : [  
> > > {"text" : { "inner\_thing.first\_name" :  
> > > "Dan" }},  
> > > {"text" : { "inner\_thing.last\_name" :  
> > > "Pilone"}}  
> > > ]  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > }
> > > 
> > > '
> > > 
> > > Still digging... -- Dan
> > > 
> > > On Jul 24, 10:56 am, Dan Pilone [d...@element84.com](mailto:d...@element84.com) wrote:
> > > 
> > > > All,  
> > > > I'm stuck. We have an index of approx 100M documents with lots of  
> > > > parent/child relationships. Some of our parent/child queries are  
> > > > extremely slow so we wanted to look at the new nested object/query  
> > > > capabilities in 0.17.1. We tried converting one of our parent/child  
> > > > relationships over but couldn't ever find results. Figuring we just  
> > > > had something wrong with our query generation I started putting  
> > > > together a really simple example but I can't get that working either.  
> > > > Can someone please help?
> > > 
> > > > First, I started with a completely new elastic 0.17.1 install.  
> > > > Next, create an index as follows:
> > > 
> > > > curl -XPUThttp://localhost:9200/echo-d'{ "settings" : { "index" :  
> > > > { "number\_of\_shards" : 3 } } }'
> > > 
> > > > Then I loaded a simple mapping:
> > > 
> > > > curl -XPUThttp://localhost:9200/echo/dataset/\_mapping-d'  
> > > > {  
> > > > "dataset": {  
> > > > "properties": {  
> > > > "provider\_id":{"type":"string","index":"not\_analyzed"},  
> > > > "inner\_thing" : {  
> > > > "type" : "nested",  
> > > > "properties" : {  
> > > > "first\_name" : { "type" : "string", "index" :  
> > > > "not\_analyzed"},  
> > > > "last\_name" : { "type" : "string", "index" :  
> > > > "not\_analyzed"}  
> > > > }  
> > > > }  
> > > > }  
> > > > }
> > > 
> > > > }'
> > > 
> > > > Then index a document:
> > > 
> > > > curl -XPOSThttp://localhost:9200/\_bulk-d'  
> > > > {"index":{"\_index":"echo","\_type":"dataset","\_id":"C1000000000-  
> > > > PROV2"}}  
> > > > {"provider\_id":"PROV2", "inner\_thing.first\_name" : "Dan",  
> > > > "inner\_thing.last\_name" : "Pilone"}  
> > > > '
> > > 
> > > > Finally, try to find it:
> > > 
> > > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d'  
> > > > {  
> > > > "query" : {  
> > > > "filtered" : {  
> > > > "query" : { "match\_all" : {} },  
> > > > "filter" : {  
> > > > "nested" : {  
> > > > "path" : "inner\_thing",  
> > > > "query" : {  
> > > > "bool" : {  
> > > > "must" : [  
> > > > {"text" : { "inner\_thing.first\_name" :  
> > > > "Dan" }},  
> > > > {"text" : { "inner\_thing.last\_name" :  
> > > > "Pilone"}}  
> > > > ]  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }}
> > > 
> > > > '
> > > 
> > > > I even tried a simpler one:
> > > 
> > > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d'  
> > > > {  
> > > > "query" : {  
> > > > "filtered" : {  
> > > > "query" : { "match\_all" : {} },  
> > > > "filter" : {  
> > > > "nested" : {  
> > > > "path" : "inner\_thing",  
> > > > "query" : {  
> > > > "bool" : {  
> > > > "must" : {  
> > > > "text" : { "first\_name" : "Dan" }  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }}
> > > 
> > > > '
> > > 
> > > > If I drop the conditions, this works:
> > > 
> > > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d'  
> > > > {  
> > > > "query" : { "match\_all" : {} }}
> > > 
> > > > '
> > > 
> > > > I'm stuck.... what am I missing? Thanks -- Dan

---

<div class="post-metadata">

**Author:** ![AnthonyNystrom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anthonynystrom/32/1066_2.png) [@AnthonyNystrom](https://discuss.elastic.co/u/AnthonyNystrom)\
**Post date:** [July 25, 2011, 1:14pm UTC](https://discuss.elastic.co/t/cant-find-anything-with-nested-queries-with-0-17-1/4938/7 "2011-07-25T13:14:45Z")

</div>

x^x

-----Original Message-----  
From: Nicolas Lalevée [nicolas.lalevee@hibnet.org](mailto:nicolas.lalevee@hibnet.org)  
Date: Mon, 25 Jul 2011 11:13:03  
To: [users@elasticsearch.com](mailto:users@elasticsearch.com)  
Reply-To: [users@elasticsearch.com](mailto:users@elasticsearch.com)  
Subject: Re: Can't find anything with nested queries with 0.17.1

Thank you Dan for your monologue, it helped me understand what nested documents and nested query actually are 🙂

If I can suggest improvement to the documentation, it would be great if it can state which "document" is actually returned by a nested query.

> **[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.

It doesn't really state that querying nested doc returned the "root" doc. Maybe obvious, but not that clear to me.

And in that page the links which references the nested mapping is broken.

Nicolas

Le 24 juil. 2011 à 17:14, Dan Pilone a écrit :

> Ok, apparently the secret to solving any problem is to post it  
> somewhere public where you can prove you don't know what you're  
> doing. Another typo in my indexing. Now both queries work as  
> expected:
> 
> curl -XPOST [http://localhost:9200/\_bulk](http://localhost:9200/_bulk) -d '{"index":  
> {"\_index":"echo","\_type":"dataset","\_id":"C1000000000-PROV2"}}  
> {"provider\_id":"PROV2", "inner\_thing" :{ "first\_name" : "Dan",  
> "last\_name" : "Pilone"}}  
> '
> 
> Now both queries work and find that document. On to testing multiple  
> "inner\_thing"s. Thanks for listening. -- Dan
> 
> On Jul 24, 11:12 am, Dan Pilone [d...@element84.com](mailto:d...@element84.com) wrote:
> 
> > Sigh - ok, not two seconds after posting that I realized where I  
> > messed up in creating the inner object. You should index the document  
> > like this:
> > 
> > curl -XPOSThttp://localhost:9200/\_bulk-d '{"index":  
> > {"\_index":"echo","\_type":"dataset","\_id":"C1000000000-PROV2"}}  
> > {"provider\_id":"PROV2", "inner\_thing" :{ "first\_name" : "Dan",  
> > "inner\_thing.last\_name" : "Pilone"}}  
> > '
> > 
> > That makes this search work as expected:
> > 
> > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d  
> > '  
> > {  
> > "query" : {  
> > "filtered" : {  
> > "query" : { "match\_all" : {} },  
> > "filter" : {  
> > "nested" : {  
> > "path" : "inner\_thing",  
> > "query" : {  
> > "bool" : {  
> > "must" : {  
> > "text" : { "first\_name" : "Dan" }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > }
> > 
> > '
> > 
> > But still doesn't get this one working:  
> > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d  
> > '  
> > {  
> > "query" : {  
> > "filtered" : {  
> > "query" : { "match\_all" : {} },  
> > "filter" : {  
> > "nested" : {  
> > "path" : "inner\_thing",  
> > "query" : {  
> > "bool" : {  
> > "must" : [  
> > {"text" : { "inner\_thing.first\_name" :  
> > "Dan" }},  
> > {"text" : { "inner\_thing.last\_name" :  
> > "Pilone"}}  
> > ]  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > }
> > 
> > '
> > 
> > Still digging... -- Dan
> > 
> > On Jul 24, 10:56 am, Dan Pilone [d...@element84.com](mailto:d...@element84.com) wrote:
> > 
> > > All,  
> > > I'm stuck. We have an index of approx 100M documents with lots of  
> > > parent/child relationships. Some of our parent/child queries are  
> > > extremely slow so we wanted to look at the new nested object/query  
> > > capabilities in 0.17.1. We tried converting one of our parent/child  
> > > relationships over but couldn't ever find results. Figuring we just  
> > > had something wrong with our query generation I started putting  
> > > together a really simple example but I can't get that working either.  
> > > Can someone please help?
> > 
> > > First, I started with a completely new elastic 0.17.1 install.  
> > > Next, create an index as follows:
> > 
> > > curl -XPUThttp://localhost:9200/echo-d'{ "settings" : { "index" :  
> > > { "number\_of\_shards" : 3 } } }'
> > 
> > > Then I loaded a simple mapping:
> > 
> > > curl -XPUThttp://localhost:9200/echo/dataset/\_mapping-d'  
> > > {  
> > > "dataset": {  
> > > "properties": {  
> > > "provider\_id":{"type":"string","index":"not\_analyzed"},  
> > > "inner\_thing" : {  
> > > "type" : "nested",  
> > > "properties" : {  
> > > "first\_name" : { "type" : "string", "index" :  
> > > "not\_analyzed"},  
> > > "last\_name" : { "type" : "string", "index" :  
> > > "not\_analyzed"}  
> > > }  
> > > }  
> > > }  
> > > }
> > 
> > > }'
> > 
> > > Then index a document:
> > 
> > > curl -XPOSThttp://localhost:9200/\_bulk-d'  
> > > {"index":{"\_index":"echo","\_type":"dataset","\_id":"C1000000000-  
> > > PROV2"}}  
> > > {"provider\_id":"PROV2", "inner\_thing.first\_name" : "Dan",  
> > > "inner\_thing.last\_name" : "Pilone"}  
> > > '
> > 
> > > Finally, try to find it:
> > 
> > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d'  
> > > {  
> > > "query" : {  
> > > "filtered" : {  
> > > "query" : { "match\_all" : {} },  
> > > "filter" : {  
> > > "nested" : {  
> > > "path" : "inner\_thing",  
> > > "query" : {  
> > > "bool" : {  
> > > "must" : [  
> > > {"text" : { "inner\_thing.first\_name" :  
> > > "Dan" }},  
> > > {"text" : { "inner\_thing.last\_name" :  
> > > "Pilone"}}  
> > > ]  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }}
> > 
> > > '
> > 
> > > I even tried a simpler one:
> > 
> > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d'  
> > > {  
> > > "query" : {  
> > > "filtered" : {  
> > > "query" : { "match\_all" : {} },  
> > > "filter" : {  
> > > "nested" : {  
> > > "path" : "inner\_thing",  
> > > "query" : {  
> > > "bool" : {  
> > > "must" : {  
> > > "text" : { "first\_name" : "Dan" }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }}
> > 
> > > '
> > 
> > > If I drop the conditions, this works:
> > 
> > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d'  
> > > {  
> > > "query" : { "match\_all" : {} }}
> > 
> > > '
> > 
> > > I'm stuck.... what am I missing? Thanks -- Dan

---

<div class="post-metadata">

**Author:** ![Dan\_Pilone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dan_pilone/32/3261_2.png) [@Dan\_Pilone](https://discuss.elastic.co/u/Dan_Pilone)\
**Post date:** [July 25, 2011, 5:29pm UTC](https://discuss.elastic.co/t/cant-find-anything-with-nested-queries-with-0-17-1/4938/8 "2011-07-25T17:29:37Z")

</div>

I'm glad someone got value out of my rambling. Anyway, to close the  
loop, with 0.17.1 and the nested document queries we're seeing  
dramatically improved performance versus parent/child querying. If  
you're on the fence about transition, it really made a huge (order of  
magnitude+) difference to our searches. Now I am a little concerned  
about how "experimental" this feature is, but we're going to  
transition to it for now due to the dramatic difference it made in  
performance. Thanks again for the great work. -- Dan

On Jul 25, 9:14 am, "Anthony Nystrom" [nystrom.anth...@gmail.com](mailto:nystrom.anth...@gmail.com)  
wrote:

> x^x
> 
> -----Original Message-----  
> From: Nicolas Lalevée [nicolas.lale...@hibnet.org](mailto:nicolas.lale...@hibnet.org)  
> Date: Mon, 25 Jul 2011 11:13:03  
> To: [us...@elasticsearch.com](mailto:us...@elasticsearch.com)
> 
> Reply-To: [us...@elasticsearch.com](mailto:us...@elasticsearch.com)  
> Subject: Re: Can't find anything with nested queries with 0.17.1
> 
> Thank you Dan for your monologue, it helped me understand what nested documents and nested query actually are 🙂
> 
> If I can suggest improvement to the documentation, it would be great if it can state which "document" is actually returned by a nested query.[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html)  
> It doesn't really state that querying nested doc returned the "root" doc. Maybe obvious, but not that clear to me.
> 
> And in that page the links which references the nested mapping is broken.
> 
> Nicolas
> 
> Le 24 juil. 2011 à 17:14, Dan Pilone a écrit :
> 
> > Ok, apparently the secret to solving any problem is to post it  
> > somewhere public where you can prove you don't know what you're  
> > doing. Another typo in my indexing. Now both queries work as  
> > expected:
> 
> > curl -XPOSThttp://localhost:9200/\_bulk-d '{"index":  
> > {"\_index":"echo","\_type":"dataset","\_id":"C1000000000-PROV2"}}  
> > {"provider\_id":"PROV2", "inner\_thing" :{ "first\_name" : "Dan",  
> > "last\_name" : "Pilone"}}  
> > '
> 
> > Now both queries work and find that document. On to testing multiple  
> > "inner\_thing"s. Thanks for listening. -- Dan
> 
> > On Jul 24, 11:12 am, Dan Pilone [d...@element84.com](mailto:d...@element84.com) wrote:
> > 
> > > Sigh - ok, not two seconds after posting that I realized where I  
> > > messed up in creating the inner object. You should index the document  
> > > like this:
> 
> > > curl -XPOSThttp://localhost:9200/\_bulk-d'{"index":  
> > > {"\_index":"echo","\_type":"dataset","\_id":"C1000000000-PROV2"}}  
> > > {"provider\_id":"PROV2", "inner\_thing" :{ "first\_name" : "Dan",  
> > > "inner\_thing.last\_name" : "Pilone"}}  
> > > '
> 
> > > That makes this search work as expected:
> 
> > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d  
> > > '  
> > > {  
> > > "query" : {  
> > > "filtered" : {  
> > > "query" : { "match\_all" : {} },  
> > > "filter" : {  
> > > "nested" : {  
> > > "path" : "inner\_thing",  
> > > "query" : {  
> > > "bool" : {  
> > > "must" : {  
> > > "text" : { "first\_name" : "Dan" }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> 
> > > }
> 
> > > '
> 
> > > But still doesn't get this one working:  
> > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d  
> > > '  
> > > {  
> > > "query" : {  
> > > "filtered" : {  
> > > "query" : { "match\_all" : {} },  
> > > "filter" : {  
> > > "nested" : {  
> > > "path" : "inner\_thing",  
> > > "query" : {  
> > > "bool" : {  
> > > "must" : [  
> > > {"text" : { "inner\_thing.first\_name" :  
> > > "Dan" }},  
> > > {"text" : { "inner\_thing.last\_name" :  
> > > "Pilone"}}  
> > > ]  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> 
> > > }
> 
> > > '
> 
> > > Still digging... -- Dan
> 
> > > On Jul 24, 10:56 am, Dan Pilone [d...@element84.com](mailto:d...@element84.com) wrote:
> 
> > > > All,  
> > > > I'm stuck. We have an index of approx 100M documents with lots of  
> > > > parent/child relationships. Some of our parent/child queries are  
> > > > extremely slow so we wanted to look at the new nested object/query  
> > > > capabilities in 0.17.1. We tried converting one of our parent/child  
> > > > relationships over but couldn't ever find results. Figuring we just  
> > > > had something wrong with our query generation I started putting  
> > > > together a really simple example but I can't get that working either.  
> > > > Can someone please help?
> 
> > > > First, I started with a completely new elastic 0.17.1 install.  
> > > > Next, create an index as follows:
> 
> > > > curl -XPUThttp://localhost:9200/echo-d'{ "settings" : { "index" :  
> > > > { "number\_of\_shards" : 3 } } }'
> 
> > > > Then I loaded a simple mapping:
> 
> > > > curl -XPUThttp://localhost:9200/echo/dataset/\_mapping-d'  
> > > > {  
> > > > "dataset": {  
> > > > "properties": {  
> > > > "provider\_id":{"type":"string","index":"not\_analyzed"},  
> > > > "inner\_thing" : {  
> > > > "type" : "nested",  
> > > > "properties" : {  
> > > > "first\_name" : { "type" : "string", "index" :  
> > > > "not\_analyzed"},  
> > > > "last\_name" : { "type" : "string", "index" :  
> > > > "not\_analyzed"}  
> > > > }  
> > > > }  
> > > > }  
> > > > }
> 
> > > > }'
> 
> > > > Then index a document:
> 
> > > > curl -XPOSThttp://localhost:9200/\_bulk-d'  
> > > > {"index":{"\_index":"echo","\_type":"dataset","\_id":"C1000000000-  
> > > > PROV2"}}  
> > > > {"provider\_id":"PROV2", "inner\_thing.first\_name" : "Dan",  
> > > > "inner\_thing.last\_name" : "Pilone"}  
> > > > '
> 
> > > > Finally, try to find it:
> 
> > > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d'  
> > > > {  
> > > > "query" : {  
> > > > "filtered" : {  
> > > > "query" : { "match\_all" : {} },  
> > > > "filter" : {  
> > > > "nested" : {  
> > > > "path" : "inner\_thing",  
> > > > "query" : {  
> > > > "bool" : {  
> > > > "must" : [  
> > > > {"text" : { "inner\_thing.first\_name" :  
> > > > "Dan" }},  
> > > > {"text" : { "inner\_thing.last\_name" :  
> > > > "Pilone"}}  
> > > > ]  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }}
> 
> > > > '
> 
> > > > I even tried a simpler one:
> 
> > > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d'  
> > > > {  
> > > > "query" : {  
> > > > "filtered" : {  
> > > > "query" : { "match\_all" : {} },  
> > > > "filter" : {  
> > > > "nested" : {  
> > > > "path" : "inner\_thing",  
> > > > "query" : {  
> > > > "bool" : {  
> > > > "must" : {  
> > > > "text" : { "first\_name" : "Dan" }  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }}
> 
> > > > '
> 
> > > > If I drop the conditions, this works:
> 
> > > > curl -XGEThttp://localhost:9200/echo/dataset/\_search?pretty=true-d'  
> > > > {  
> > > > "query" : { "match\_all" : {} }}
> 
> > > > '
> 
> > > > I'm stuck.... what am I missing? Thanks -- Dan

---

<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:59am UTC](https://discuss.elastic.co/t/cant-find-anything-with-nested-queries-with-0-17-1/4938/9 "2017-07-06T03:59:32Z")

</div>


