module Article::Searchable extend ActiveSupport::Concern
included do include Elasticsearch::Model
index_name "green_application"
settings index: { number_of_shards: 1, number_of_replicas: 0, analysis: { analyzer: { kuromoji_analyzer: { type: 'custom', tokenizer: 'kuromoji_tokenizer', filter: ['kuromoji_baseform', 'pos_filter', 'greek_lowercase_filter', 'cjk_width'], }, ngram_analyzer: { tokenizer: "ngram_tokenizer" } } } } do mapping _source: { enabled: true }, _all: { enabled: true, analyzer: "kuromoji_analyzer" } do indexes :id, type: 'integer', index: 'not_analyzed' indexes :title, type: 'string', analyzer: 'kuromoji_analyzer' end end
def as_indexed_json(options={}) hash = self.as_json( include: { job_types: { only: [:job_type_id] }, } ) hash['client_name'] = client.name
hash end end
module ClassMethods def create_index!(options={}) client = __elasticsearch__.client client.indices.delete index: "green_application" rescue nil if options[:force] client.indices.create index: "green_application", body: { settings: settings.to_hash, mappings: mappings.to_hash } end end end
|