这是我的ActiveRecord定义
settings index: { number_of_shards: 1, number_of_replicas: 0 } do
mappings do
indexes :cas, type: 'string', index: "not_analyzed", analyzer: 'snowball'
indexes :names, type: 'string', analyzer: 'snowball'
indexes :names_cn, type: 'string', analyzer: 'ik_max_word'
indexes :suggest, type: 'completion', analyzer: 'snowball'
indexes :suggest_cn, type: 'completion', analyzer: 'ik_max_word'
end
end
def as_indexed_json(options = {})
{
cas: self.cas.to_s.strip,
names: self.suggests,
names_cn: self.suggests_cn,
suggest: { input: self.suggests },
suggest_cn: { input: self.chinese_keywords }
}
end
这就是elasticsearch服务器向我展示的内容
{
"something-development": {
"aliases": {},
"mappings": {
"chemicals": {
"properties": {
"cas": {
"type": "string"
},
"names": {
"type": "string"
},
"names_cn": {
"type": "string"
},
"suggest": {
"properties": {
"input": {
"type": "string"
}
}
},
"suggest_cn": {
"properties": {
"input": {
"type": "string"
}
}
}
}
}
},
"settings": {
"index": {
"creation_date": "1470383173607",
"number_of_shards": "5",
"number_of_replicas": "1",
"uuid": "a8ONu0WSRGuImjLRU6ddVg",
"version": {
"created": "2030499"
}
}
},
"warmers": {}
}
}
我认为这个建议& suggest_cn项应该是这样的:类型完成
suggest": {
"type": "completion",
"analyzer": "snowball",
"payloads": false,
"preserve_separators": true,
"preserve_position_increments": true,
"max_input_length": 50
}
也许我在理解这个问题时遇到了一些问题。任何人都有帮助(祝福)
https://github.com/elastic/elasticsearch-rails/issues/612我也有问题。
答案 0 :(得分:0)
使用Chemical.__elasticsearch__.create_index! force: true
而不是Chemical.__elasticsearch__.client.indices.create index: Chemical.index_name