1

As the title says, I want to make the following query from rails with the elasticsearch-rails gem.

curl -XGET "localhost:9200/my_index/_count?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "term": {
      "my_field": 12
    }
  }
}
'

I have tried this:

MyModel.search("cats", search_type: 'count').results.total

and I get Elasticsearch::Transport::Transport::Errors::BadRequest ([400] {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"No search type for [count]"}],"type":"illegal_argument_exception","reason":"No search type for [count]"},"status":400})

The curl call works fine from the console.

Despite some people thinking that count has been deprecated the Count API seems alive and well in ES 7.7 - https://www.elastic.co/guide/en/elasticsearch/reference/current/search-count.html

phil
  • 4,668
  • 4
  • 33
  • 51

0 Answers0