Elasticsearch无法找到geo_point字段,如何更正向域添加映射?

时间:2017-05-23 12:14:41

标签: 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"
               }
            }
         }
      }
   }
}

1 个答案:

答案 0 :(得分:2)

根据您的映射,geo_cord字段的类型为text,如果您想在geo_point查询中使用它,则该字段应为geo_distance。< / p>

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

并确保在查询中使用place.location.geo_cord代替location.geo_cord