fullscale / elastic.js

A JavaScript implementation of the elasticsearch Query DSL
http://docs.fullscale.co/elasticjs/
MIT License
654 stars 163 forks source link

No facets for count queries #13

Closed juniorplenty closed 11 years ago

juniorplenty commented 11 years ago

Using the _search endpoint with query param search_type=count allows facets to be used with count queries, and is just as performant as the _count endpoint. Currently, elastic.js doesn't provide an option to utilize this execution path.

To enable this, the doCount method should change:

var queryData = JSON.stringify(query.query);

to:

var queryData = JSON.stringify(query);

...and should set:

params.search_type="count"

(and other query types should clear that params entry)

juniorplenty commented 11 years ago

More info on search_type:

http://www.elasticsearch.org/guide/reference/api/search/search-type/

mattweber commented 11 years ago

The do* methods are for the end points. I will expose setting the search_type parameter and you can then set that to "count" and use the doSearch method to achieve what you want.

ejs.Request({indices:test})
    .searchType('count')
    .facet(whateverFacet)
    .doSearch() 

Should be pretty easy to expose the search types, I will have a look right now.

mattweber commented 11 years ago

Support for search types here.

https://github.com/fullscale/elastic.js/commit/23747ae3a7ecbed285814cee5878513a7e5d8918

juniorplenty commented 11 years ago

Perfect, thanks!