Git Product home page Git Product logo

Comments (5)

mrkamel avatar mrkamel commented on May 18, 2024

Use .total_count or .total_entries like stated in the readme and reference docs
https://www.rubydoc.info/github/mrkamel/search_flip/SearchFlip/Response#total_entries-instance_method

MyIndex.where(field_id: 12).total_count

from search_flip.

erictuvesson avatar erictuvesson commented on May 18, 2024

Awesome, thanks!

I tried to find anything about it in the readme, just I was looking more for count and total_count is not there.

from search_flip.

erictuvesson avatar erictuvesson commented on May 18, 2024

It still doesn't work in the way I expect.

irb(main):006:0> Index.range(:created_at_date, gt: date, lte: date + 1.day).total_entries
=> 10000
irb(main):007:0> Index.where(master_module_id: 12).total_entries
=> 10000
irb(main):008:0> Index.where(master_module_id: 12).total_count  
=> 10000

I looked into the code and it's still doing the same search query where I want to do a count query.

https://github.com/mrkamel/search_flip/blob/master/lib/search_flip/response.rb#L42

Elasticsearch (Count API)
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-count.html

from search_flip.

mrkamel avatar mrkamel commented on May 18, 2024

search flip is not using the COUNT API, because then you would always need two queries: one to get the results, and one to get the count.

ES always returns 10_000, because since version 7, ES by default stops counting from 10_000 on for performance reasons. To get the exact number of results for ES > 7, you have to add track_total_hits(true), e.g.

Index.where(...).track_total_hits(true).total_count

from search_flip.

erictuvesson avatar erictuvesson commented on May 18, 2024

Okay, I was aware of the 10_000 limit, just not aware of the API call to make it all visible.

irb(main):005:0> Index.range(:created_at_date, gt: date, lte: date + 1.day).where(master_module_id: 12).track_total_hits(true).total_count
=> 1490200

Thanks for the help again!

from search_flip.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.