# Faceted search fails when the script field regards to more than 1 level deep property

**URL:** <https://discuss.elastic.co/t/faceted-search-fails-when-the-script-field-regards-to-more-than-1-level-deep-property/7793>\
**Category:** Elasticsearch\
**Created:** [May 21, 2012, 10:00pm UTC](https://discuss.elastic.co/t/faceted-search-fails-when-the-script-field-regards-to-more-than-1-level-deep-property/7793 "2012-05-21T22:00:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Treff7es](https://avatars.discourse-cdn.com/v4/letter/t/9fc348/32.png) [@Treff7es](https://discuss.elastic.co/u/Treff7es)\
**Post date:** [May 21, 2012, 10:00pm UTC](https://discuss.elastic.co/t/faceted-search-fails-when-the-script-field-regards-to-more-than-1-level-deep-property/7793/1 "2012-05-21T22:00:06Z")

</div>

Hi,

I started to use faceted search with elastic and it works quite well and  
fast, but it always fails if I try to use Terms facet with a script field  
that is pointing to property which depth is more than 1 level deep. (for  
example \_source.prop.prop1)  
It is only fails if the query resultset has at least 1 document that does  
not have that property I'm looking for. So for example if I'm looking for  
\_source.prop.prop1 then it fails if I have at least one document that don't  
have the \_source.prop.prop1 property in the resultset.  
I think correctly the faceted search should skip those documents that does  
not have the faceted property and it should not throw a PropertyAccessException[[Error:  
could not access: prop; exeception, which happens if the property depth is  
1.

For example this query fails:  
{"query":{"query\_string":{"query":"\*"}},"facets":{"termStatFacet":{"terms":{"size":500,"script":"\_source.prop.prop1"}}}}'

But this query not:  
{"query":{"query\_string":{"query":"\*"}},"facets":{"termStatFacet":{"terms":{"size":500,"script":"\_source.testProperty"}}}}

However the first query won't fail if I use a query that matches on every  
document that has a property I'm using in term facet :  
{"query":{"query\_string":{"query":"prop.prop1:\*"}},"facets":{"termStatFacet":{"terms":{"size":500,"script":"\_source.prop.prop1"}}}}'

For more information see:

> <https://gist.github.com/treff7es/2764851>

Is this how it should work or it is a bug?

Thanks,  
Tamas

---

<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:** [May 23, 2012, 10:46pm UTC](https://discuss.elastic.co/t/faceted-search-fails-when-the-script-field-regards-to-more-than-1-level-deep-property/7793/2 "2012-05-23T22:46:46Z")

</div>

mvel support null value property navigation using the .? syntax, here is  
how it should look like: curl -XGET  
[http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search) -d  
'{"query":{"query\_string":{"query":"\*"}},"facets":{"termStatFacet":{"terms":{"size":500,"script":"\_source.?prop.?prop1"}}}}'.

Note, faceting on \_source means that for each hit that matches the query,  
the \_source will be loaded and parsed, using doc prefix usually makes more  
sense.

On Tue, May 22, 2012 at 12:00 AM, Treff7es [treff7es@gmail.com](mailto:treff7es@gmail.com) wrote:

> Hi,
> 
> I started to use faceted search with elastic and it works quite well and  
> fast, but it always fails if I try to use Terms facet with a script field  
> that is pointing to property which depth is more than 1 level deep. (for  
> example \_source.prop.prop1)  
> It is only fails if the query resultset has at least 1 document that does  
> not have that property I'm looking for. So for example if I'm looking for  
> \_source.prop.prop1 then it fails if I have at least one document that don't  
> have the \_source.prop.prop1 property in the resultset.  
> I think correctly the faceted search should skip those documents that does  
> not have the faceted property and it should not throw a PropertyAccessException[[Error:  
> could not access: prop; exeception, which happens if the property depth is  
> 1.
> 
> For example this query fails:
> 
> {"query":{"query\_string":{"query":"\*"}},"facets":{"termStatFacet":{"terms":{"size":500,"script":"\_source.prop.prop1"}}}}'
> 
> But this query not:
> 
> {"query":{"query\_string":{"query":"\*"}},"facets":{"termStatFacet":{"terms":{"size":500,"script":"\_source.testProperty"}}}}
> 
> However the first query won't fail if I use a query that matches on every  
> document that has a property I'm using in term facet :
> 
> {"query":{"query\_string":{"query":"prop.prop1:\*"}},"facets":{"termStatFacet":{"terms":{"size":500,"script":"\_source.prop.prop1"}}}}'
> 
> For more information see:  
> [Facet search with \_script property which is more than 2 level depth · GitHub](https://gist.github.com/2764851)
> 
> Is this how it should work or it is a bug?
> 
> Thanks,  
> Tamas

---

<div class="post-metadata">

**Author:** ![Treff7es](https://avatars.discourse-cdn.com/v4/letter/t/9fc348/32.png) [@Treff7es](https://discuss.elastic.co/u/Treff7es)\
**Post date:** [May 25, 2012, 6:21am UTC](https://discuss.elastic.co/t/faceted-search-fails-when-the-script-field-regards-to-more-than-1-level-deep-property/7793/3 "2012-05-25T06:21:33Z")

</div>

Hi,

Thanks Shay for the answer.  
My soulution was adding an exist filter for the requested property to the  
facet query.

What do you mean on doc prefix?

I used \_source because for example for "Acme Institute" I wanted to get  
back as "Acme Institute" and not as "Acme" and "Institute" however when I'm  
doing search I wanted to be searchable with "Acme" and "Institue" so I  
couldn't use Keyword analyzer for the expression.

Thanks,  
Tamas

On Thursday, May 24, 2012 12:46:46 AM UTC+2, kimchy wrote:

> mvel support null value property navigation using the .? syntax, here is  
> how it should look like: curl -XGET  
> [http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search) -d  
> '{"query":{"query\_string":{"query":"\*"}},"facets":{"termStatFacet":{"terms":{"size":500,"script":"\_source.?prop.?prop1"}}}}'.
> 
> Note, faceting on \_source means that for each hit that matches the query,  
> the \_source will be loaded and parsed, using doc prefix usually makes more  
> sense.
> 
> On Tue, May 22, 2012 at 12:00 AM, Treff7es [treff7es@gmail.com](mailto:treff7es@gmail.com) wrote:
> 
> > Hi,
> > 
> > I started to use faceted search with elastic and it works quite well and  
> > fast, but it always fails if I try to use Terms facet with a script field  
> > that is pointing to property which depth is more than 1 level deep. (for  
> > example \_source.prop.prop1)  
> > It is only fails if the query resultset has at least 1 document that does  
> > not have that property I'm looking for. So for example if I'm looking for  
> > \_source.prop.prop1 then it fails if I have at least one document that don't  
> > have the \_source.prop.prop1 property in the resultset.  
> > I think correctly the faceted search should skip those documents that  
> > does not have the faceted property and it should not throw a PropertyAccessException[[Error:  
> > could not access: prop; exeception, which happens if the property depth is  
> > 1.
> > 
> > For example this query fails:
> > 
> > {"query":{"query\_string":{"query":"\*"}},"facets":{"termStatFacet":{"terms":{"size":500,"script":"\_source.prop.prop1"}}}}'
> > 
> > But this query not:
> > 
> > {"query":{"query\_string":{"query":"\*"}},"facets":{"termStatFacet":{"terms":{"size":500,"script":"\_source.testProperty"}}}}
> > 
> > However the first query won't fail if I use a query that matches on every  
> > document that has a property I'm using in term facet :
> > 
> > {"query":{"query\_string":{"query":"prop.prop1:\*"}},"facets":{"termStatFacet":{"terms":{"size":500,"script":"\_source.prop.prop1"}}}}'
> > 
> > For more information see:  
> > [Facet search with \_script property which is more than 2 level depth · GitHub](https://gist.github.com/2764851)
> > 
> > Is this how it should work or it is a bug?
> > 
> > Thanks,  
> > Tamas

On Thursday, May 24, 2012 12:46:46 AM UTC+2, kimchy wrote:

> mvel support null value property navigation using the .? syntax, here is  
> how it should look like: curl -XGET  
> [http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search) -d  
> '{"query":{"query\_string":{"query":"\*"}},"facets":{"termStatFacet":{"terms":{"size":500,"script":"\_source.?prop.?prop1"}}}}'.
> 
> Note, faceting on \_source means that for each hit that matches the query,  
> the \_source will be loaded and parsed, using doc prefix usually makes more  
> sense.
> 
> On Tue, May 22, 2012 at 12:00 AM, Treff7es [treff7es@gmail.com](mailto:treff7es@gmail.com) wrote:
> 
> > Hi,
> > 
> > I started to use faceted search with elastic and it works quite well and  
> > fast, but it always fails if I try to use Terms facet with a script field  
> > that is pointing to property which depth is more than 1 level deep. (for  
> > example \_source.prop.prop1)  
> > It is only fails if the query resultset has at least 1 document that does  
> > not have that property I'm looking for. So for example if I'm looking for  
> > \_source.prop.prop1 then it fails if I have at least one document that don't  
> > have the \_source.prop.prop1 property in the resultset.  
> > I think correctly the faceted search should skip those documents that  
> > does not have the faceted property and it should not throw a PropertyAccessException[[Error:  
> > could not access: prop; exeception, which happens if the property depth is  
> > 1.
> > 
> > For example this query fails:
> > 
> > {"query":{"query\_string":{"query":"\*"}},"facets":{"termStatFacet":{"terms":{"size":500,"script":"\_source.prop.prop1"}}}}'
> > 
> > But this query not:
> > 
> > {"query":{"query\_string":{"query":"\*"}},"facets":{"termStatFacet":{"terms":{"size":500,"script":"\_source.testProperty"}}}}
> > 
> > However the first query won't fail if I use a query that matches on every  
> > document that has a property I'm using in term facet :
> > 
> > {"query":{"query\_string":{"query":"prop.prop1:\*"}},"facets":{"termStatFacet":{"terms":{"size":500,"script":"\_source.prop.prop1"}}}}'
> > 
> > For more information see:  
> > [Facet search with \_script property which is more than 2 level depth · GitHub](https://gist.github.com/2764851)
> > 
> > Is this how it should work or it is a bug?
> > 
> > Thanks,  
> > Tamas

On Thursday, May 24, 2012 12:46:46 AM UTC+2, kimchy wrote:

> mvel support null value property navigation using the .? syntax, here is  
> how it should look like: curl -XGET  
> [http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search) -d  
> '{"query":{"query\_string":{"query":"\*"}},"facets":{"termStatFacet":{"terms":{"size":500,"script":"\_source.?prop.?prop1"}}}}'.
> 
> Note, faceting on \_source means that for each hit that matches the query,  
> the \_source will be loaded and parsed, using doc prefix usually makes more  
> sense.
> 
> On Tue, May 22, 2012 at 12:00 AM, Treff7es [treff7es@gmail.com](mailto:treff7es@gmail.com) wrote:
> 
> > Hi,
> > 
> > I started to use faceted search with elastic and it works quite well and  
> > fast, but it always fails if I try to use Terms facet with a script field  
> > that is pointing to property which depth is more than 1 level deep. (for  
> > example \_source.prop.prop1)  
> > It is only fails if the query resultset has at least 1 document that does  
> > not have that property I'm looking for. So for example if I'm looking for  
> > \_source.prop.prop1 then it fails if I have at least one document that don't  
> > have the \_source.prop.prop1 property in the resultset.  
> > I think correctly the faceted search should skip those documents that  
> > does not have the faceted property and it should not throw a PropertyAccessException[[Error:  
> > could not access: prop; exeception, which happens if the property depth is  
> > 1.
> > 
> > For example this query fails:
> > 
> > {"query":{"query\_string":{"query":"\*"}},"facets":{"termStatFacet":{"terms":{"size":500,"script":"\_source.prop.prop1"}}}}'
> > 
> > But this query not:
> > 
> > {"query":{"query\_string":{"query":"\*"}},"facets":{"termStatFacet":{"terms":{"size":500,"script":"\_source.testProperty"}}}}
> > 
> > However the first query won't fail if I use a query that matches on every  
> > document that has a property I'm using in term facet :
> > 
> > {"query":{"query\_string":{"query":"prop.prop1:\*"}},"facets":{"termStatFacet":{"terms":{"size":500,"script":"\_source.prop.prop1"}}}}'
> > 
> > For more information see:  
> > [Facet search with \_script property which is more than 2 level depth · GitHub](https://gist.github.com/2764851)
> > 
> > Is this how it should work or it is a bug?
> > 
> > Thanks,  
> > Tamas

---

<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:** [May 29, 2012, 6:27pm UTC](https://discuss.elastic.co/t/faceted-search-fails-when-the-script-field-regards-to-more-than-1-level-deep-property/7793/4 "2012-05-29T18:27:18Z")

</div>

\_source ends up loading each json doc and parsing it, doc will preload all  
the data to memory and make accessing it considerably faster. You can map  
the field as not analyzed and then use doc on that field, which will give  
you the content without it being broken down to terms. You can also use  
multi field mapping to have one version analyzed, and one that is not.

On Fri, May 25, 2012 at 8:21 AM, Treff7es [treff7es@gmail.com](mailto:treff7es@gmail.com) wrote:

> Hi,
> 
> Thanks Shay for the answer.  
> My soulution was adding an exist filter for the requested property to the  
> facet query.
> 
> What do you mean on doc prefix?
> 
> I used \_source because for example for "Acme Institute" I wanted to get  
> back as "Acme Institute" and not as "Acme" and "Institute" however when I'm  
> doing search I wanted to be searchable with "Acme" and "Institue" so I  
> couldn't use Keyword analyzer for the expression.
> 
> Thanks,  
> Tamas
> 
> On Thursday, May 24, 2012 12:46:46 AM UTC+2, kimchy wrote:
> 
> > mvel support null value property navigation using the .? syntax, here is  
> > how it should look like: curl -XGET [http://localhost:9200/twitter/](http://localhost:9200/twitter/)\*\*  
> > tweet/\_search [http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search) -d  
> > '{"query":{"query\_string":{" **query":"\*"}},"facets":{"**  
> > termStatFacet":{"terms":{" **size":500,"script":"\_source.?**  
> > prop.?prop1"}}}}'.
> > 
> > Note, faceting on \_source means that for each hit that matches the query,  
> > the \_source will be loaded and parsed, using doc prefix usually makes more  
> > sense.
> > 
> > On Tue, May 22, 2012 at 12:00 AM, Treff7es [treff7es@gmail.com](mailto:treff7es@gmail.com) wrote:
> > 
> > > Hi,
> > > 
> > > I started to use faceted search with elastic and it works quite well and  
> > > fast, but it always fails if I try to use Terms facet with a script field  
> > > that is pointing to property which depth is more than 1 level deep. (for  
> > > example \_source.prop.prop1)  
> > > It is only fails if the query resultset has at least 1 document that  
> > > does not have that property I'm looking for. So for example if I'm looking  
> > > for \_source.prop.prop1 then it fails if I have at least one document that  
> > > don't have the \_source.prop.prop1 property in the resultset.  
> > > I think correctly the faceted search should skip those documents that  
> > > does not have the faceted property and it should not throw a  
> > > PropertyAccessException[[\*\*Error: could not access: prop; exeception,  
> > > which happens if the property depth is 1.
> > > 
> > > For example this query fails:  
> > > {"query":{"query\_string":{" **query":"\*"}},"facets":{"**  
> > > termStatFacet":{"terms":{" **size":500,"script":"\_source.**  
> > > prop.prop1"}}}}'
> > > 
> > > But this query not:  
> > > {"query":{"query\_string":{" **query":"\*"}},"facets":{"**  
> > > termStatFacet":{"terms":{" **size":500,"script":"\_source.**  
> > > testProperty"}}}}
> > > 
> > > However the first query won't fail if I use a query that matches on  
> > > every document that has a property I'm using in term facet :  
> > > {"query":{"query\_string":{" **query":"prop.prop1:\*"}},"**  
> > > facets":{"termStatFacet":{" **terms":{"size":500,"script":"\_**  
> > > source.prop.prop1"}}}}'
> > > 
> > > For more information see:  
> > > [https://gist.github.com/\*\*2764851](https://gist.github.com/**2764851) [https://gist.github.com/2764851](https://gist.github.com/2764851)
> > > 
> > > Is this how it should work or it is a bug?
> > > 
> > > Thanks,  
> > > Tamas
> 
> On Thursday, May 24, 2012 12:46:46 AM UTC+2, kimchy wrote:
> 
> > mvel support null value property navigation using the .? syntax, here is  
> > how it should look like: curl -XGET [http://localhost:9200/twitter/](http://localhost:9200/twitter/)\*\*  
> > tweet/\_search [http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search) -d  
> > '{"query":{"query\_string":{" **query":"\*"}},"facets":{"**  
> > termStatFacet":{"terms":{" **size":500,"script":"\_source.?**  
> > prop.?prop1"}}}}'.
> > 
> > Note, faceting on \_source means that for each hit that matches the query,  
> > the \_source will be loaded and parsed, using doc prefix usually makes more  
> > sense.
> > 
> > On Tue, May 22, 2012 at 12:00 AM, Treff7es [treff7es@gmail.com](mailto:treff7es@gmail.com) wrote:
> > 
> > > Hi,
> > > 
> > > I started to use faceted search with elastic and it works quite well and  
> > > fast, but it always fails if I try to use Terms facet with a script field  
> > > that is pointing to property which depth is more than 1 level deep. (for  
> > > example \_source.prop.prop1)  
> > > It is only fails if the query resultset has at least 1 document that  
> > > does not have that property I'm looking for. So for example if I'm looking  
> > > for \_source.prop.prop1 then it fails if I have at least one document that  
> > > don't have the \_source.prop.prop1 property in the resultset.  
> > > I think correctly the faceted search should skip those documents that  
> > > does not have the faceted property and it should not throw a  
> > > PropertyAccessException[[\*\*Error: could not access: prop; exeception,  
> > > which happens if the property depth is 1.
> > > 
> > > For example this query fails:  
> > > {"query":{"query\_string":{" **query":"\*"}},"facets":{"**  
> > > termStatFacet":{"terms":{" **size":500,"script":"\_source.**  
> > > prop.prop1"}}}}'
> > > 
> > > But this query not:  
> > > {"query":{"query\_string":{" **query":"\*"}},"facets":{"**  
> > > termStatFacet":{"terms":{" **size":500,"script":"\_source.**  
> > > testProperty"}}}}
> > > 
> > > However the first query won't fail if I use a query that matches on  
> > > every document that has a property I'm using in term facet :  
> > > {"query":{"query\_string":{" **query":"prop.prop1:\*"}},"**  
> > > facets":{"termStatFacet":{" **terms":{"size":500,"script":"\_**  
> > > source.prop.prop1"}}}}'
> > > 
> > > For more information see:  
> > > [https://gist.github.com/\*\*2764851](https://gist.github.com/**2764851) [https://gist.github.com/2764851](https://gist.github.com/2764851)
> > > 
> > > Is this how it should work or it is a bug?
> > > 
> > > Thanks,  
> > > Tamas
> 
> On Thursday, May 24, 2012 12:46:46 AM UTC+2, kimchy wrote:
> 
> > mvel support null value property navigation using the .? syntax, here is  
> > how it should look like: curl -XGET [http://localhost:9200/twitter/](http://localhost:9200/twitter/)\*\*  
> > tweet/\_search [http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search) -d  
> > '{"query":{"query\_string":{" **query":"\*"}},"facets":{"**  
> > termStatFacet":{"terms":{" **size":500,"script":"\_source.?**  
> > prop.?prop1"}}}}'.
> > 
> > Note, faceting on \_source means that for each hit that matches the query,  
> > the \_source will be loaded and parsed, using doc prefix usually makes more  
> > sense.
> > 
> > On Tue, May 22, 2012 at 12:00 AM, Treff7es [treff7es@gmail.com](mailto:treff7es@gmail.com) wrote:
> > 
> > > Hi,
> > > 
> > > I started to use faceted search with elastic and it works quite well and  
> > > fast, but it always fails if I try to use Terms facet with a script field  
> > > that is pointing to property which depth is more than 1 level deep. (for  
> > > example \_source.prop.prop1)  
> > > It is only fails if the query resultset has at least 1 document that  
> > > does not have that property I'm looking for. So for example if I'm looking  
> > > for \_source.prop.prop1 then it fails if I have at least one document that  
> > > don't have the \_source.prop.prop1 property in the resultset.  
> > > I think correctly the faceted search should skip those documents that  
> > > does not have the faceted property and it should not throw a  
> > > PropertyAccessException[[\*\*Error: could not access: prop; exeception,  
> > > which happens if the property depth is 1.
> > > 
> > > For example this query fails:  
> > > {"query":{"query\_string":{" **query":"\*"}},"facets":{"**  
> > > termStatFacet":{"terms":{" **size":500,"script":"\_source.**  
> > > prop.prop1"}}}}'
> > > 
> > > But this query not:  
> > > {"query":{"query\_string":{" **query":"\*"}},"facets":{"**  
> > > termStatFacet":{"terms":{" **size":500,"script":"\_source.**  
> > > testProperty"}}}}
> > > 
> > > However the first query won't fail if I use a query that matches on  
> > > every document that has a property I'm using in term facet :  
> > > {"query":{"query\_string":{" **query":"prop.prop1:\*"}},"**  
> > > facets":{"termStatFacet":{" **terms":{"size":500,"script":"\_**  
> > > source.prop.prop1"}}}}'
> > > 
> > > For more information see:  
> > > [https://gist.github.com/\*\*2764851](https://gist.github.com/**2764851) [https://gist.github.com/2764851](https://gist.github.com/2764851)
> > > 
> > > Is this how it should work or it is a bug?
> > > 
> > > Thanks,  
> > > Tamas

---

<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:26am UTC](https://discuss.elastic.co/t/faceted-search-fails-when-the-script-field-regards-to-more-than-1-level-deep-property/7793/5 "2017-07-06T03:26:31Z")

</div>


