Skip to content

Results returns 10, records returns 62000 #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mmahalwy opened this issue Aug 14, 2014 · 12 comments
Closed

Results returns 10, records returns 62000 #206

mmahalwy opened this issue Aug 14, 2014 · 12 comments

Comments

@mmahalwy
Copy link

.results returns 10, I can change the size, but when I change it to 50, it returns 20.

When I do .records it returns 62000, which is the correct number.

Don't know what methods to use with results to output even more than 50!

@anlek
Copy link

anlek commented Aug 19, 2014

I'm getting a similar thing using es-rails with Mongoid. Also, my indexes don't seem to be searchable at all.

@mmahalwy
Copy link
Author

Yeah, it's not working properly? :S

@paxer
Copy link

paxer commented Aug 22, 2014

same here :(

@mmahalwy
Copy link
Author

I'm not using mongoid, and getting this problem. Hopefully it's fixed ASAP
cause this is a disaster for my app! :(

On Friday, August 22, 2014, Pavel Kotlyar [email protected] wrote:

same here :(


Reply to this email directly or view it on GitHub
#206 (comment)
.

Mohamed El Mahallawy

@mmahalwy4167101981

@karmi
Copy link
Contributor

karmi commented Aug 22, 2014

Please post the code you're using, and try to emulate the behaviour in integration tests, eg. https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-model/test/integration/active_record_basic_test.rb#L139-L141

@paxer paxer mentioned this issue Aug 25, 2014
@onemanstartup
Copy link

It's the same thing as #215
You just need to set size param to bigger value.
In my controller

@topics = Topic.search(params[:q]).records.records.where(user: current_user).page(params[:page]).per(10)

and in my model

@search_definition[:size]  = 100

But I'm in doubt that it is right thing to do. @karmi what is the right way?

@karmi
Copy link
Contributor

karmi commented Aug 27, 2014

@onemanstartup I still don't understand the problem from the incomplete code examples and descriptions in this ticket :)

@onemanstartup
Copy link

@karmi

    def self.search(query, options={})
      __set_filters = lambda do |key, f|

        @search_definition[:filter][:and] ||= []
        @search_definition[:filter][:and]  |= [f]
      end

      @search_definition = {
        query: {},
        filter: {},
      }

      unless query.blank?
        @search_definition[:query] = {
          bool: {
            should: [
              { multi_match: {
                query: query,
                fields: ['title^10', 'body'],
                operator: 'and',
                analyzer: 'russian_morphology_custom'
              }
              }
            ]
          }
        }
        @search_definition[:sort]  = { updated_at: 'desc' }
        # Without that parameter default is 10
        @search_definition[:size]  = 100
      else
        @search_definition[:query] = { match_all: {} }
        @search_definition[:sort]  = { updated_at: 'desc' }
      end
      __elasticsearch__.search(@search_definition)
    end

If i want to query for item that belongs to user through active_record relations I need all items and then apply paging. But in this situation records returns only 10 items. It is not obvious why.
Maybe i just don't need query relation and instead indexing what i need to search. But I don't know how to query then.

Sorry for my stupidity :)

@karmi
Copy link
Contributor

karmi commented Aug 27, 2014

But in this situation records returns only 10 items

By default, ES will always return just 10 results, that's expected. Use the size parameter for the search method, as you do, that's correct. I still don't know what's unexpected here and what would you like to do...

... .where(user: current_user). ...

Why don't you search on this field, that way you limit the search only for results for current_user.

Maybe i just don't need query relation and instead indexing what i need to search.

Yes, always :)

@karmi
Copy link
Contributor

karmi commented Aug 29, 2014

Any news here? I don't see the problem.

@mmahalwy
Copy link
Author

mmahalwy commented Sep 1, 2014

@karmi see my other issue. Commented on it!

@karmi karmi closed this as completed Sep 1, 2014
@Micka33
Copy link

Micka33 commented Sep 8, 2014

Got the same issue, my problem is that I was expecting all the macthing results to be returned.

However from the documentation, it looks like this is the default behavior of ES.

I suppose that should be written somewhere in the README as one would expect it's database/ORM/whatever to return all the matchings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants