Need a little help with facet query


(Tomasz Kloc) #1

Hello,

I cannot find solution in documentation and I'd never used lucene-based
search engines before.

My current query looks like this:
{
"sort": [{"add_time": "desc"}],
"query": {
"filtered": {
"filter": {
"bool": {
"must": [{"term": {"category_ids": 10}}, {"range":
{"end_time": {"include_upper": false, "from": "2011-11-07T16:45:42",
"include_lower": true}}}]
}
},
"query": {"match_all": {}}
}
},
"facets": {"category_ids": {"terms": {"field": "category_ids",
"size": 5}}},
"from": 0,
"size": 10
}

category_ids is a list/array of id: [1,2,3,4..]
currently, facet contains counters for all category_ids, but i need
facets only for specific category_id, for example 1 and 4.
How can I solve that?

tk


(Clinton Gormley) #2

Hi Tomasz

"facets": {"category_ids": {"terms": {"field": "category_ids",
"size": 5}}},

category_ids is a list/array of id: [1,2,3,4..]
currently, facet contains counters for all category_ids, but i need
facets only for specific category_id, for example 1 and 4.
How can I solve that?

You can use regex patterns or exclude to filter the faceted terms:

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

clint

tk


(Tomasz Kloc) #3

Thanks.

I have some more questions:

  1. Exclude looks nice, but i rather need to include ~10 terms than
    excluding houndred. can someone give me example how to filter this facet
    only for [1,4] using regex or script?
  2. Any idea how to implement this using PYES ?
  3. Is 'term facet' the best choice (performance/memory usage) for what
    i try to do ? I need number of (filtered) ads in specific categories

On 07.11.2011 19:50, Clinton Gormley wrote:

Hi Tomasz

"facets": {"category_ids": {"terms": {"field": "category_ids",

"size": 5}}},

category_ids is a list/array of id: [1,2,3,4..]
currently, facet contains counters for all category_ids, but i need
facets only for specific category_id, for example 1 and 4.
How can I solve that?

You can use regex patterns or exclude to filter the faceted terms:

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

clint

tk


(system) #4