【发布时间】:2012-08-31 12:09:26
【问题描述】:
我们存储的文档看起来像这样:
{
"id": "dQesbpxeQniUWXpsnjPQ",
"title": "Golf in Hamburg, Altona",
"user": "CtGjEaDxSrhPbf7W7NcH",
"location": {
"id": "Q6sZhRHdiS3mP2innbJ9",
"name": "Hamburg, Altona",
"lat": 53.55,
"lon": 9.93333,
"slug": "hamburg-altona"
},
"_type": "announcement"
}
我们需要 announcement.location.slug 成为 not_analyzed(毕竟这是一个蛞蝓)
但是映射不会采取,我们有这些设置:
Tire.index(@@index_name) do
delete
create(mappings: {
announcement: {
properties: {
"id" => { type: 'string', index: 'not_analyzed' },
"user" => { type: 'string', index: 'not_analyzed' },
"location" => {
type: 'geo_point',
properties: {
"slug" => { type: 'string', index: 'not_analyzed' }
}
},
"times" => { type: 'string', analyzer: 'keyword' },
"sport" => {
"properties" => {
"slug" => { type: 'string', index: 'not_analyzed' }
}
}
}
}
},
settings: {
index: {
number_of_shards: 1,
number_of_replicas: 0
}
})
refresh
end
注意:curl 语法中的相同映射也不起作用,但对 SO 的可读性较差,因此我发布了 Ruby 代码。
似乎geo_point 正在覆盖文档该部分的所有其他映射。 The documentation 似乎同意。
我确信有一种方法可以使用 lat_lon 选项,但我找不到任何关于它如何工作的文档。 (我假设使用lat_lon 设置映射单个lat 和lon 字段)
也有可能,我曾希望使用the multi field type,但这似乎不适用于主文档属性的整个子树。
如何在不更改整个数据模型的情况下继续操作?
【问题讨论】:
标签: ruby search geolocation elasticsearch tire