I'm struggling writing an ElasticSearch query with facet counts. This is very
likely a simple question but I'm confused by all the facet filters and filter
facets.
The query itself needs two conditions:
- a condition which restricts the document set, excluded documents should
not be used for the facet count ("only display documents for a specific
user"). - a condition which restricts the result set but excluded documents should
be part of the facet count ("user filters by tag but should see other tags
in the facet count")
Example documents:
{"user": "admin", "tag": "baz"}
{"user": "editor", "tag": "foo"}
{"user": "editor", "tag": "bar"}
( curl -XPUT 'http://localhost:9200/blog/post/1' -d '...' )
query:
{
"query" : {
"constant_score": {
"filter": {"term": {"user": "editor"} }
}
},
"facets" : {
"tag" : { "terms" : {"field" : "tag"} }
}
}
The result of this query is ok, I see a facet count for tags foo+bar correctly.
Now I'd like to extend the query so the results only display documents with
tag "foo" BUT keep the facet count as before (so tag "bar" should also appear
in the facet count).
If I modify the constant_score filter like this:
"filter": {
"and": [{"term": {"user": "editor"}}, {"term": {"tag": "foo"}}]
}
Then obviously only tag "foo" will appear in the facet count so I need to add
the {"term": {"tag": "foo"}} filter somewhere else.
How do I do that in ElasticSearch?
Felix
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/5371CAA8.5070801%40oss.schwarz.eu.
For more options, visit https://groups.google.com/d/optout.