Help with facets


(Ricardo Monteiro) #1

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
Facebook - https://www.facebook.com/sitepx
Twitter - 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.
For more options, visit https://groups.google.com/groups/opt_out.


(Ivan Brusic) #2

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.

http://www.elasticsearch.org/guide/reference/api/search/facets/terms-facet/

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

Cheers,

Ivan

On Thu, Sep 5, 2013 at 8:41 AM, Ricardo Monteiro 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
Facebook - https://www.facebook.com/sitepx
Twitter - 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.
For more options, visit 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.
For more options, visit https://groups.google.com/groups/opt_out.


(rcmonteiro) #3

Problem solved, thanks!


(system) #4