Wish the search method for elasticsearch is working on rails

■The environment

・Ruby 2.4.1
・Ruby on Rails 5.1.7
・Elasticsearch 7.10.2-SNAPSHOT

・elasticsearch (7.4.0)
・elasticsearch-api (7.4.0)
・elasticsearch-model (7.1.0 80822d6)
・elasticsearch-rails (7.1.0 80822d6)
・elasticsearch-transport (7.4.0)

■My wish

Hi I'm japanese.
My wish is that read faster on database to use elasticsearch on rails.
Now i'm trouble with search method on rails.

I will explain the current settings.
First, I think the record on elastic search already input on following below.

curl 'localhost:9200/_cat/indices?v'
health status index                  uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   es_project_development Fpu_adXWT9Gtw7KZTh0aDw   1   1       6804            0      3.7mb          3.7mb

Second, the setting of index and mapping for elasticsearch are the following below.


module ProjectSearchable
    extend ActiveSupport::Concern

    included do
      include Elasticsearch::Model

      index_name "es_project_#{Rails.env}"

      settings do
        mappings dynamic: 'false' do
          indexes :id,          type: 'integer'
          indexes :title,   type: 'text', analyzer: 'kuromoji'
          indexes :contents,   type: 'text', analyzer: 'kuromoji'
          indexes :industry,      type: 'text'

      def as_indexed_json(*)
          .slice(:id, :title, :contents, :industry, ...)

    class_methods do
      def create_index!
        client = __elasticsearch__.client
        client.indices.delete index: self.index_name rescue nil
        client.indices.create(index: self.index_name,
          body: {
            settings: self.settings.to_hash,
            mappings: self.mappings.to_hash

      def es_search(query)
          query: {
            multi_match: {
               fields: %w(id title contents industry ...),
               type: 'cross_fields',
              query: query,
               operator: 'and'

Third, the view and the controller are the following below.


= form_tag search_path, {:method=>"get"}
    table border="0"
                = text_field_tag 'keyword[name]', nil, class: 'write'
                input.push type="submit" value=""

    def search
        @keyword = params.dig('keyword', 'name')

        params = ''
        connection = '?'


            if @keyword.present?
                params = "#{params}#{connection}keyword=#{@keyword}"
                connection = '&'


Last, ProjectSearchable is included in models/project.rb.

class Project < ApplicationRecord
    include ProjectSearchable

■The problem

On rails console, i typed command


Response was following.
※Game is included in the record

@klass=[PROXY] Project (call 'Project.connection' to establish a connection),
@klass=[PROXY] Project (call 'Project.connection' to establish a connection),

I think elasticsearch doesn't work.
My opinion of this problem is in search method for elasticsearch.
But i don't have enough knowledge about that.

I really need your help.
Thank you.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.