Need a little help with facet query

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

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:

clint

tk

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:

Elasticsearch Platform — Find real-time answers at scale | Elastic

clint

tk