# Nested query doesn't work

**URL:** <https://discuss.elastic.co/t/nested-query-doesnt-work/15800>\
**Category:** Elasticsearch\
**Created:** [February 14, 2014, 1:40pm UTC](https://discuss.elastic.co/t/nested-query-doesnt-work/15800 "2014-02-14T13:40:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aditya\_Herlambang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aditya_herlambang/32/1798_2.png) [@Aditya\_Herlambang](https://discuss.elastic.co/u/Aditya_Herlambang)\
**Post date:** [February 14, 2014, 1:40pm UTC](https://discuss.elastic.co/t/nested-query-doesnt-work/15800/1 "2014-02-14T13:40:05Z")

</div>

I have the following setup:

indexes:  
website:  
client: default  
finder: ~  
settings:  
index:  
analysis:  
analyzer:  
my\_analyzer:  
type: custom  
tokenizer: lowercase  
filter : [my\_ngram]  
filter:  
my\_ngram:  
type: "edgeNGram"  
min\_gram: 2  
max\_gram: 5  
types:  
shop:  
mappings:  
username: { boost: 3 }  
fullname: { boost: 2 }  
bio: { boost: 1 }  
userPictures:  
type: "nested"  
properties:  
caption: { boost: 5 }  
persistence:  
driver: orm  
model: App\MainBundle\Entity\InstagramShop  
provider: ~  
listener: ~

and here's my nested query in PHP:

```
            $finder = 

```

$this-\>container-\>get('fos\_elastica.finder.website');

```
            $mainQuery = new \Elastica\Query\Bool();
            $shopQuery = new \Elastica\Query\QueryString();
            $shopQuery->setParam('query', $searchquery);
            $shopQuery->setParam('fields', array(
                'username', 'bio', 'fullname'
            ));

            $pictureQuery = new \Elastica\Query\QueryString();
            $pictureQuery->setParam('query', $searchquery);
            $pictureQuery->setParam('fields', array(
                'caption'
            ));

            $nestedQuery = new \Elastica\Query\Nested();
            $nestedQuery->setPath('userPictures');
            $nestedQuery->setQuery($pictureQuery);

            $mainQuery->addShould($shopQuery);
            $mainQuery->addShould($nestedQuery);

            $items = $finder->find($mainQuery);

```

I wonder why this only matches with the shopQuery and not with the  
nestedQuery. Here's the structure for the InstagramShop class:

class InstagramShop  
{

```
/**
 * @Exclude()
 * @ORM\OneToMany(targetEntity="InstagramShopPicture", mappedBy="shop", 

```

cascade={"persist"})  
\* @ORM\OrderBy({"created" = "DESC"})  
\*/  
protected $userPictures;

```
/**
 * Get attributes
 *
 * @return \Doctrine\Common\Collections\Collection 
 */
public function getUserpictures()
{
    return $this->userPictures;
}

```

}

User pictures here is a collection of InstagramShopPicture which has a  
caption of type string

Any idea why it can't find userPictures caption?

--  
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/9277d215-7feb-4087-a08b-ef7b8a4d9ca9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9277d215-7feb-4087-a08b-ef7b8a4d9ca9%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, 1:50am UTC](https://discuss.elastic.co/t/nested-query-doesnt-work/15800/2 "2017-07-06T01:50:08Z")

</div>


