我有一个简单的存储库来保存我的状态日志
class OrderStatusRepository
include Elasticsearch::Persistence::Repository
include Elasticsearch::Persistence::Repository::DSL
def index_name
"statuses-#{ Time.now.strftime('%Y-%m')}"
end
mapping do
indexes :src_location, type: 'geo_point'
indexes :dst_location, type: 'geo_point'
end
end
当我添加一些数据时,问题是没有应用Map。
{"id":158,"src_location":"1.486912, 2.493157","dst_location":"11.489026, -22.501309"}
"dst_location": {
"type": "text", #NOT GEOPOINT !!!!
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
我可以手动创建索引和Map,但它有动态名称,我不会每月/每天都这样做。
有没有办法让这一切自动化?谢谢。
1条答案
按热度按时间wwodge7n1#
您可以使用索引模板来定义将在索引创建时自动应用的模板。模板可以包括设置和Map。
对于您的数据,您可以创建这样一个索引模板,它将匹配任何匹配的索引
foo-*
以及bar-*
```PUT/ _template/foobar
{
"index_patterns": [
"foo-",
"bar-"
],
"mappings": {
"properties": {
"id": {
"type": "keyword"
},
"src_location": {
"type": "geo_point"
},
"dst_location": {
"type": "geo_point"
}
}
}
}
POST/ foo-1/_doc/1
{
"id": 158,
"src_location": "1.486912, 2.493157",
"dst_location": "11.489026, -22.501309"
}
GET /foo-1/_mapping
{
"foo-1": {
"mappings": {
"properties": {
"dst_location": {
"type": "geo_point"
},
"id": {
"type": "keyword"
},
"src_location": {
"type": "geo_point"
}
}
}
}
}