elasticsearch 如何自动将位置映射到地理点?弹性搜索,elasticsearch,elasticsearch" /> elasticsearch 如何自动将位置映射到地理点?弹性搜索,elasticsearch,elasticsearch" />

elasticsearch 如何自动将位置映射到地理点?弹性搜索

elasticsearch 如何自动将位置映射到地理点?弹性搜索,elasticsearch,elasticsearch,我想知道如何将每个名为“location”的字段设置为类型“geo\u point” 我可以使用默认映射吗?如果是,我找不到任何例子 还是应该使用动态模板 谢谢您可以使用动态模板。以下是创建索引时如何执行此操作的示例: curl -XPOST localhost:9200/test -d '{ "settings": { "number_of_shards": 1 }, "mappings": { "_default_:": { "_ttl": true,

我想知道如何将每个名为
“location”
的字段设置为类型
“geo\u point”

我可以使用默认映射吗?如果是,我找不到任何例子

还是应该使用动态模板


谢谢

您可以使用动态模板。以下是创建索引时如何执行此操作的示例:

 curl -XPOST localhost:9200/test -d '{
"settings": {
    "number_of_shards": 1
},
"mappings": {
    "_default_:": {
        "_ttl": true,
        "dynamic_templates": [
            {
                "geo_location": {
                    "mapping": {
                        "type": "geo_point"
                    },
                    "match": "location"
                }
            }
        ]
    }
}
}'

这个应该放在哪里?感谢您调整了答案,以显示在创建索引时是如何完成的。这也可以通过put映射完成。我会尽快尝试。谢谢,我不确定它是否真的有效。我的意思是,当我对数据重新编制索引后再查看映射时。它说
“位置”
是动态的,
“lat”
“lon”
是双重的。这正常吗?然后当我尝试使用geo_距离进行过滤查询时,它只返回所有数据。