I'm using the query below to find the word "developer" in a blog index...
http://localhost:9200/blog/_search
{
"query": {
"query_string": {
"query": "developer"
}
}
}
The query returns 3 hits on user
and 1 hit on post
types, and I want a facet to reflect those hits to display something like...
Search Results...
Blogs Posts (1)
Users (3)
...but I'm not sure how to combine a facet with a query to count such hits since most examples I found count field hits; I tried using _index
to return index hits, but could not get it to work; is there something similar for types, like _type
, to count document type hits within an index?
Ok, figured it out, apparently there is a _type
field for facets, based on this...
http://elasticsearch-users.115913.n3.nabble.com/enabled-quot-index-quot-does-not-allow-me-to-get-facet-values-td1056215.html
Query
http://localhost:9200/blog/_search
{
"size" : 0,
"query" : {
"query_string" : {
"query" : "developer"}
},
"facets" : {
"type" : {
"terms" : { "field" : "_type"}
}
}
}
Response
{
...
"facets": {
"type": {
"_type": "terms",
"missing": 0,
"total": 4,
"other": 0,
"terms": [
{
"term": "user",
"count": 3
},
{
"term": "post",
"count": 1
}
]
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With