elasticsearch-rails icon indicating copy to clipboard operation
elasticsearch-rails copied to clipboard

NoMethodError: undefined method `find' for nil:NilClass

Open Sexual opened this issue 6 years ago • 5 comments

In production, we can't search in multiple models. it works fine locally.

Elasticsearch version v7.4.2

    search_payload = {
      query: {
        bool: {
          must: [
            {
              multi_match: {
                query: params[:search].to_s.downcase
              }
            }
          ],
          must_not: {
            exists: {
              field: 'deleted_at'
            }
          },
          filter: [
            {
              term: {
                user_: user_shop.id,
              }
            }
          ]
        }
      },
      size: 7
    }

records = Elasticsearch::Model.search(search_payload, [Order, Product]).records
records.json
NoMethodError: undefined method `find' for nil:NilClass
from /usr/local/bundle/gems/elasticsearch-model-7.0.0/lib/elasticsearch/model/adapters/multiple.rb:79:in `__records_for_klass'

Sexual avatar Nov 24 '19 16:11 Sexual

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 31 '20 13:08 stale[bot]

@Sexual Did you find solution?

meoooh avatar Feb 24 '21 03:02 meoooh

@meoooh If this is still an issue for you, what version of the gem and stack are you using? I'll take a look as soon as it's possible.

picandocodigo avatar Feb 24 '21 10:02 picandocodigo

@picandocodigo

elasticsearch (7.10.1)
      elasticsearch-api (= 7.10.1)
      elasticsearch-transport (= 7.10.1)
    elasticsearch-api (7.10.1)
      multi_json
    elasticsearch-model (7.1.1)
      activesupport (> 3)
      elasticsearch (> 1)
      hashie
    elasticsearch-rails (7.1.1)
    elasticsearch-transport (7.10.1)
      faraday (~> 1)
      multi_json

meoooh avatar Feb 25 '21 01:02 meoooh

I am also running into this bug. I tracked it down to a failure to match __type_for_hit in vendor/bundle/gems/elasticsearch-model-7.1.1/lib/elasticsearch/model/adapters/multiple.rb:109

In our case we use index aliases so model.index_name == hit[:_index] will never be true. Also seems like with ElasticSearch deprecating the _type and document_type fields this will need to be reworked before ES 8 support is added.

seanvm avatar Nov 17 '22 22:11 seanvm