# Help with facets

**URL:** <https://discuss.elastic.co/t/help-with-facets/13478>\
**Category:** Elasticsearch\
**Created:** [September 5, 2013, 3:41pm UTC](https://discuss.elastic.co/t/help-with-facets/13478 "2013-09-05T15:41:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ricardo\_Monteiro](https://avatars.discourse-cdn.com/v4/letter/r/a698b9/32.png) [@Ricardo\_Monteiro](https://discuss.elastic.co/u/Ricardo_Monteiro)\
**Post date:** [September 5, 2013, 3:41pm UTC](https://discuss.elastic.co/t/help-with-facets/13478/1 "2013-09-05T15:41:22Z")

</div>

Hi!

I just start using Elastic search with no background about Lucene, just a  
little experience using AWS CloudSearch.

Here is my problem:

That's my mapping:

curl -XPUT http://[URL]:9200/log -d '  
{  
"mappings": {  
"log": {  
"properties": {  
"session": {"type": "string"},  
"visitor": {"type": "string"},  
"site": {"type": "integer"},  
"access": {"type": "date", "format" : "yyyy-MM-dd  
HH:mm:ss"},  
"request": {"type": "string", "index" : "not\_analyzed"},  
"referer": {"type": "string", "index" : "not\_analyzed"},  
"first": {"type": "integer"},  
"ip": {"type": "ip"},  
"user\_agent": {"type": "string"},  
"city": {"type": "string", "index" : "not\_analyzed"},  
"country": {"type": "string", "index" : "not\_analyzed"},  
"ll": {"type": "geo\_point"}  
}  
}  
}  
}'

I want to retrieve just the counts of facet referer in documents on log,  
for that i made this search:

curl -X POST "http://[URL]:9200/log/log/\_search?pretty=true" -d '  
{  
"query" : {  
"term" : {  
"first" : "1"  
}  
},  
"filter" : {  
"range" : {  
"access" : {  
"to" : "2013-08-05 23:59:59",  
"from" : "2013-08-01 00:00:00"  
}  
}  
},  
"facets" : {  
"request" : {  
"terms" : {  
"field" : "referer",  
"size" : "10"  
},  
"facet\_filter" : {  
"term" : {  
"site" : "190794"  
}  
}  
}  
},  
"size" : "0"  
}'

So far so good, i got it all the referer from site 190794, but i don't want  
to retrieve empty referers, for this i try using the filter "exists : {  
"field" : "referer" }" but this dont work on my code.  
I know i dont get it yet the structure to use filter, facets and queries,  
anybody can help me?

Thanks in advance!

## Ricardo Monteiro

SitePX - [http://www.sitepx.com](http://www.sitepx.com)  
Facebook - [https://www.facebook.com/sitepx](https://www.facebook.com/sitepx)  
Twitter - [https://twitter.com/sitepx](https://twitter.com/sitepx)

--  
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:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [September 5, 2013, 4:14pm UTC](https://discuss.elastic.co/t/help-with-facets/13478/2 "2013-09-05T16:14:56Z")

</div>

Is the field missing or simply index with an empty value of ""? It appears  
your scenario is the latter. Try explicitly excluding the empty string from  
your facet.

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

"terms" : {  
"field" : "referer",  
"size" : "10",  
"exclude" : [""]  
}

Cheers,

Ivan

On Thu, Sep 5, 2013 at 8:41 AM, Ricardo Monteiro [ricardo@sitepx.com](mailto:ricardo@sitepx.com) wrote:

> Hi!
> 
> I just start using Elastic search with no background about Lucene, just a  
> little experience using AWS CloudSearch.
> 
> Here is my problem:
> 
> That's my mapping:
> 
> curl -XPUT http://[URL]:9200/log -d '  
> {  
> "mappings": {  
> "log": {  
> "properties": {  
> "session": {"type": "string"},  
> "visitor": {"type": "string"},  
> "site": {"type": "integer"},  
> "access": {"type": "date", "format" : "yyyy-MM-dd  
> HH:mm:ss"},  
> "request": {"type": "string", "index" : "not\_analyzed"},  
> "referer": {"type": "string", "index" : "not\_analyzed"},  
> "first": {"type": "integer"},  
> "ip": {"type": "ip"},  
> "user\_agent": {"type": "string"},  
> "city": {"type": "string", "index" : "not\_analyzed"},  
> "country": {"type": "string", "index" : "not\_analyzed"},  
> "ll": {"type": "geo\_point"}  
> }  
> }  
> }  
> }'
> 
> I want to retrieve just the counts of facet referer in documents on log,  
> for that i made this search:
> 
> curl -X POST "http://[URL]:9200/log/log/\_search?pretty=true" -d '  
> {  
> "query" : {  
> "term" : {  
> "first" : "1"  
> }  
> },  
> "filter" : {  
> "range" : {  
> "access" : {  
> "to" : "2013-08-05 23:59:59",  
> "from" : "2013-08-01 00:00:00"  
> }  
> }  
> },  
> "facets" : {  
> "request" : {  
> "terms" : {  
> "field" : "referer",  
> "size" : "10"  
> },  
> "facet\_filter" : {  
> "term" : {  
> "site" : "190794"  
> }  
> }  
> }  
> },  
> "size" : "0"  
> }'
> 
> So far so good, i got it all the referer from site 190794, but i don't  
> want to retrieve empty referers, for this i try using the filter "exists :  
> { "field" : "referer" }" but this dont work on my code.  
> I know i dont get it yet the structure to use filter, facets and queries,  
> anybody can help me?
> 
> Thanks in advance!
> 
> ## Ricardo Monteiro
> 
> SitePX - [http://www.sitepx.com](http://www.sitepx.com)  
> Facebook - [Facebook](https://www.facebook.com/sitepx)  
> Twitter - [https://twitter.com/sitepx](https://twitter.com/sitepx)
> 
> --  
> 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:** ![rcmonteiro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rcmonteiro/32/2104_2.png) [@rcmonteiro](https://discuss.elastic.co/u/rcmonteiro)\
**Post date:** [September 5, 2013, 4:53pm UTC](https://discuss.elastic.co/t/help-with-facets/13478/3 "2013-09-05T16:53:52Z")

</div>

Problem solved, thanks!

---

<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:17am UTC](https://discuss.elastic.co/t/help-with-facets/13478/4 "2017-07-06T02:17:57Z")

</div>


