gpt4 book ai didi

javascript - Elasticsearch 5.3 - 找不到 geo_point 字段

转载 作者:行者123 更新时间:2023-11-29 20:56:35 27 4
gpt4 key购买 nike

我指的是这个 Geo Distance Query Elasticsearch 文档中给出的示例。

版本:5.3

按照教程,我执行了这个查询以在索引中插入数据

PUT /my_locations/location/1
{
"pin" : {
"location" : {
"lat" : 40.12,
"lon" : -71.34
}
}
}

然后我只是尝试应用也在文档中显示的地理距离查询。

GET /my_locations/location/_search
{
"query": {
"bool" : {
"must" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "200km",
"pin.location" : {
"lat" : 40,
"lon" : -70
}
}
}
}
}
}

但它向我显示了这个错误。“找不到 geo_point 字段 [pin.location]”其他时候它告诉我这个错误“字段 [pin.location] 不是 geo_point 字段”。

我是否需要以不同的方式插入这条记录,或者我是否在查询中遗漏了一些参数?

最佳答案

谢谢@Pierre Mallet

我查看了文档并得出结论,我首先需要使用 geo_point 数据类型创建索引。我无法在现有索引上应用数据类型。所以我的步骤是这样的

PUT gym
{
"mappings": {
"gyms": {
"properties": {
"location": {
"type": "geo_point"
}
}
}
}
}

插入包含位置的记录

PUT gym/gyms/1
{
"location" : [ -71.34, 41.12 ]
}

然后查找索引及其数据类型

GET /gym/gyms/_mapping/

您将看到位置字段具有 geo_point 数据类型。然后您可以执行查询。

GET gym/gyms/_search
{
"query": {
"bool" : {
"must" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "150km",
"location" : [ -70.34, 40.12 ]
}
}
}
}
}

现在一切正常。

关于javascript - Elasticsearch 5.3 - 找不到 geo_point 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49030060/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com