我正在尝试为我的模型创建一个自定义索引以供Elasticsearch服务使用。我以某种方式只能呈现一个结构(选定的列),而没有记录。

我的模特:

require 'elasticsearch/model'

class Lead < ApplicationRecord
  include Elasticsearch::Model
  include Elasticsearch::Model::Callbacks

   mappings dynamic: false do
      indexes :id, type: 'keyword'
      indexes :lead_status, type: 'keyword'
      indexes :country
      indexes :city
      indexes :title
      indexes :description
      indexes :contact_person
    end
end

然后,我尝试从Rails控制台创建索引:
2.5.1 :004 > Lead.__elasticsearch__.create_index!(force:true)
2018-11-26 04:19:55 +0100: DELETE http://localhost:9200/leads [status:404, request:0.034s, query:N/A]
2018-11-26 04:19:55 +0100: < {"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"leads","index_uuid":"_na_","index":"leads"}],"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"leads","index_uuid":"_na_","index":"leads"},"status":404}
2018-11-26 04:19:55 +0100: [404] {"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"leads","index_uuid":"_na_","index":"leads"}],"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"leads","index_uuid":"_na_","index":"leads"},"status":404}
[!!!] Index does not exist (Elasticsearch::Transport::Transport::Errors::NotFound)
2018-11-26 04:19:55 +0100: HEAD http://localhost:9200/leads [status:404, request:0.007s, query:N/A]
2018-11-26 04:19:55 +0100: <
2018-11-26 04:19:55 +0100: [404]
2018-11-26 04:19:56 +0100: PUT http://localhost:9200/leads [status:200, request:0.707s, query:n/a]
2018-11-26 04:19:56 +0100: > {"settings":{},"mappings":{"_doc":{"dynamic":false,"properties":{"id":{"type":"keyword"},"lead_status":{"type":"keyword"},"country":{"type":"text"},"city":{"type":"text"},"title":{"type":"text"},"description":{"type":"text"},"contact_person":{"type":"text"}}}}}
2018-11-26 04:19:56 +0100: < {"acknowledged":true,"shards_acknowledged":true,"index":"leads"}
 => {"acknowledged"=>true, "shards_acknowledged"=>true, "index"=>"leads"}

之后,在/ leads上的本地elasticsearch服务器上,我可以看到我的自定义结构,但是没有任何记录。如何解决此问题?

Rails版本:5.2.1
Elasticsearch:6.4.3
elasticsearch-model / rails gem :6.0.0

最佳答案

我对这种类型的东西使用es flex 。但是从elasticsearch的输出来看,它只是创建索引,您必须为对象建立索引,以使它们显示在elasticsearch中。

通过浏览文档,看起来您可以通过执行Lead.import进行导入

关于ruby-on-rails - Rails-elasticsearch:无法执行表的自定义映射内容,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53474460/

10-11 09:09
查看更多