elasticsearch - Elasticsearch找不到geo_point字段,如何正确添加到字段的映射?

标签 elasticsearch mapping

这是我来自http://localhost:9200/fb_events/_search的示例结果

    [...]
    "hits": {
    "total": 18,
    "max_score": 1,
    "hits": [
    {
    "_index": "fb_events",
    "_type": "event",
    "_id": "AVw1MpQDmr08c_VMq0b_",
    "_score": 1,
    "_source": {
    "description": "desc",
    "start_time": "2017-11-17T20:00:00+0100",
    "place": {
    "id": "496893413669851",
    "name": "Dwa Światy",
    "location": {
    "city": "Torun",
    "zip": "87-100",
    "country": "Poland",
    "longitude": 18.603430234931,
    "street": "ul. Ducha św. 10/12",
    "latitude": 53.009319027091,
    "geo_cord": "18.6034302349,53.0093190271"
    }
    },
    "end_time": "2017-11-17T23:00:00+0100",
    "id": "622266071285763",
    "name": "Podwórkowi Chuligani (XX-lecie) + TBA - Toruń / Dwa Światy"
    }
    }
}
[...]

我想根据位置搜索记录。这是我的查询:
 query = {
        "size": 100,
        "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter": {"geo_distance": {"distance": distance, "geo_cord": {"lat": lat, "lon": lon}}}
        }
      }
    }

但是当我执行此操作时,出现错误RequestError: TransportError(400, u'search_phase_execution_exception', u'failed to find geo_point field [geo_cord]')
我的问题是,我该怎么办?将映射添加到此字段?

编辑:
GET /fb_events/_mapping/event的输出
{
   "fb_events": {
      "mappings": {
         "event": {
            "properties": {
               "description": {
                  "type": "text",
                  "fields": {
                     "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                     }
                  }
               },
               "end_time": {
                  "type": "date"
               },
               "id": {
                  "type": "text",
                  "fields": {
                     "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                     }
                  }
               },
               "name": {
                  "type": "text",
                  "fields": {
                     "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                     }
                  }
               },
               "place": {
                  "properties": {
                     "id": {
                        "type": "text",
                        "fields": {
                           "keyword": {
                              "type": "keyword",
                              "ignore_above": 256
                           }
                        }
                     },
                     "location": {
                        "properties": {
                           "city": {
                              "type": "text",
                              "fields": {
                                 "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                 }
                              }
                           },
                           "country": {
                              "type": "text",
                              "fields": {
                                 "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                 }
                              }
                           },
                           "geo_cord": {
                              "type": "text",
                              "fields": {
                                 "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                 }
                              }
                           },
                           "latitude": {
                              "type": "float"
                           },
                           "longitude": {
                              "type": "float"
                           },
                           "street": {
                              "type": "text",
                              "fields": {
                                 "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                 }
                              }
                           },
                           "zip": {
                              "type": "text",
                              "fields": {
                                 "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                 }
                              }
                           }
                        }
                     },
                     "name": {
                        "type": "text",
                        "fields": {
                           "keyword": {
                              "type": "keyword",
                              "ignore_above": 256
                           }
                        }
                     }
                  }
               },
               "start_time": {
                  "type": "date"
               }
            }
         }
      }
   }
}

最佳答案

根据您的映射,geo_cord字段的类型为text,但如果要在geo_point查询中使用它,则应为geo_distance

在索引第一个文档之前,您需要删除索引并使用正确的映射重新创建索引。

并确保在查询中使用place.location.geo_cord而不是location.geo_cord

关于elasticsearch - Elasticsearch找不到geo_point字段,如何正确添加到字段的映射?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44134545/

相关文章:

在 Apache CXF JAX-RS 中映射扩展内容类型

mapping - ElasticSearch 映射 Charfilter

amazon-web-services - 为ElasticSearch集群增加磁盘空间的最佳方法是什么?

elasticsearch - 忽略聚合查询中的 “match”子句

java - Elasticsearch非法参数异常

mapping - Entity Framework 代码优先 - 多对多外键问题

spring-mvc - Spring MVC 映射 Guava Multimap

java - ElasticSearch - 按两个不同字段分组

javascript - d3 - 我可以以某种方式组成两个投影,或者投影一个投影吗?

mapping - Knockout.js - 映射插件以及其他属性