我是 Elasticsearch 的新手,目前正致力于实现用于搜索的 geo_distance
过滤器。截至目前,我的索引具有以下映射(我删除了一些字段):
{
advert_index: {
mappings: {
advert_type: {
properties: {
__v: {
type: "long"
},
caption: {
type: "string"
},
category: {
type: "string"
},
**location: {
type: "long"
},**
}
}
}
}
geo_distance 字段将在位置字段上实现,示例实例如下所示:
"location": [
71,
60
],
即采用 geoJSON 格式 [lon, lat]
。
我知道我必须更新我的索引,以便位置字段的类型为 geo_point
,如文档 (mapping-geo-point) 中所述。似乎我必须删除索引并创建一个新索引,但我无法做到这一点。
我走在正确的轨道上吗?如果有人可以帮助我创建新索引或使用正确的数据类型更新现有索引,我将不胜感激。
非常感谢!
最佳答案
一般来说,您可以使用put mapping api(引用here)更新您的索引映射:
curl -XPUT 'http://localhost:9200/advert_index/_mapping/advert_type' -d '
{
"advert_type" : {
"properties" : {
//your new mapping properties
}
}
}
'
它对于添加新字段特别有用。但是,在您的情况下,您将尝试更改位置类型,这将导致冲突并阻止使用新映射。
您可以使用 put mapping api 来添加另一个属性,该属性包含作为纬度/经度数组的位置,但您将无法更新之前的位置字段本身。
最后,您必须重新索引您的数据,以便将您的新映射考虑在内。
最好的解决方案确实是创建一个新索引。
如果您创建另一个索引的问题是停机时间,您应该看看 aliases让事情顺利进行。
关于indexing - 在 elasticsearch 中创建或更新映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25471715/