ElasticSearch没有在特定模型Ruby上索引新映射

时间:2014-10-20 03:55:01

标签: ruby elasticsearch

很难获得elasticsearch来索引模型中的新映射

include Elasticsearch::Model
include Elasticsearch::Model::Callbacks

settings index: { number_of_shards: 1 } do
  mappings dynamic: 'false' do
    indexes :body, type: 'string', analyzer: 'english'
    indexes :status, type: 'string'
    indexes :post_type, type: 'string'
    indexes :genre, type: 'string'
  end
end

以上是post的模型。新增内容为genre

如上所述调整模型后,还需要使弹性搜索开始显示基于新属性的结果。

每次保存时都会调用它,因此拾取它时应该没有问题

def regenerate_index!
  Post.__elasticsearch__.create_index! force: true
  Post.__elasticsearch__.refresh_index!
  Post.import
end 

所有索引输出

url 'localhost:9200/_cat/indices?v'
health index                 pri rep docs.count docs.deleted
store.size pri.store.size
yellow posts                   1   1      10871            0              1.7mb          1.7mb 

对索引进行操作似乎也有正确的映射

{
  "posts": {
    "mappings": {
      "post": {
        "dynamic": "false",
        "properties": {
          "body": {
            "type": "string",
            "analyzer": "english"
          },
          "genre": {
            "type": "string"
          },
          "post_type": {
            "type": "string"
          },
          "status": {
            "type": "string"
          }
        }
      }
    }
  }
}

无论出于何种原因,文档都没有添加所有映射:

http://localhost:9200/posts/post/10000

结果:

{
  "_index": "posts",
  "_type": "post",
  "_id": "10000",
  "_version": 1,
  "found": true,
  "_source": {
    "body": "*thinks about Frank's birds*\n*sweats*",
    "status": "new"
  }
}

0 个答案:

没有答案