弹性搜索 5.3 - 找不到 geo_point 字段
Elastic search 5.3 - failed to find geo_point field
我指的是弹性搜索文档中给出的这个 Geo Distance Query 示例。
版本: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
}
}
}
}
}
}
但它向我显示此错误。
"failed to find geo_point field [pin.location]"
其他时候它告诉我这个错误
"field [pin.location] is not a geo_point field".
我是否需要以不同的方式插入这条记录,或者我是否在查询中遗漏了一些参数?
谢谢@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 ]
}
}
}
}
}
现在一切正常。
我指的是弹性搜索文档中给出的这个 Geo Distance Query 示例。
版本: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
}
}
}
}
}
}
但它向我显示此错误。 "failed to find geo_point field [pin.location]" 其他时候它告诉我这个错误 "field [pin.location] is not a geo_point field".
我是否需要以不同的方式插入这条记录,或者我是否在查询中遗漏了一些参数?
谢谢@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 ]
}
}
}
}
}
现在一切正常。