php - Elasticsearch 地理点查询过滤器

标签 php codeigniter elasticsearch

我正在尝试将 geo_point 用于距离,但它始终显示位置类型为 double 而不是 geo_point 如何设置映射到 geo_point 的位置。

实际上我必须找到 5km 范围内的所有记录。

 "pin" : {
             "properties" : {
             "location" : {
             "properties" : {
             "lat" : {
             "type" : "double"
             },
                 "lon" : {
                 "type" : "double"
                 }
              }
              },
                  "type" : {
                  "type" : "string"
                  }
              }
              },

当我尝试使用下面的查询进行搜索以查找距离德里 lat long 5 公里以内的结果时:

 {
          "query": {
            "filtered": {
              "query": {
                "match_all": {}
              },
              "filter": {
                "pin": {
                  "distance": "5",
                  "distance_unit": "km",
                  "coordinate": {
                    "lat": 28.5402707,
                    "lon": 77.2289643
                  }
                }
              }
            }
          }
        }

它向我显示错误 query_parsing_exception 和没有为 [pin] 注册的查询。我无法弄清楚问题所在。它总是抛出这个异常

  {

            "error": {
                "root_cause": [
                    {
                        "type": "query_parsing_exception",
                        "reason": "No query registered for [pin]",
                        "index": "find_index",
                        "line": 1,
                        "col": 58
                    }
                ],
                "type": "search_phase_execution_exception",
                "reason": "all shards failed",
                "phase": "query",
                "grouped": true,
                "failed_shards": [
                    {
                        "shard": 0,
                        "index": "find_index",
                        "node": "DtpkEdLCSZCr8r2bTd8p5w",
                        "reason": {
                            "type": "query_parsing_exception",
                            "reason": "No query registered for [pin]",
                            "index": "find_index",
                            "line": 1,
                            "col": 58
                        }
                    }
                ]
            },
            "status": 400

        }

请帮我解决这个问题。我如何设置 geo_point 并解决此异常错误和状态 400 和 all_shards_failed 错误

最佳答案

你只需要像这样映射你的 pin 类型,即使用 geo_point data type :

# 1. first delete your index
DELETE shouut_find_index

# 2. create a new one with the proper mapping
PUT shouut_find_index
{
  "mappings": {
    "search_shouut": {
      "properties": {
        "location": {
          "type": "geo_point"
        },
        "type": {
          "type": "string"
        }
      }
    }
  }
}

然后你可以像这样索引一个文档

PUT shouut_find_index/search_shouut/1
{ 
   "location": {
      "lat": 28.5402707,
      "lon": 77.2289643
   },
   "type": "dummy"
}

最后你的查询看起来像这样

POST shouut_find_index/search_shouut/_search
{
  "query": {
    "filtered": {
      "filter": {
        "geo_distance": {
          "distance": "5km",
          "location": {
            "lat": 28.5402707,
            "lon": 77.2289643
          }
        }
      }
    }
  }
}

关于php - Elasticsearch 地理点查询过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36997597/

相关文章:

php - 计算逗号分隔值的用户数

php 使用容器进行依赖注入(inject)

codeigniter - 将_Id存储为MongoDB中的对象或字符串?

elasticsearch - 有没有一种方法可以通过单个查询创建多个ElasticSearch索引

php - 在 Laravel 的路由中使用 {id}

以特定方式将 PHP CSV 转换为数组

javascript - Elasticsearch 是一个单独的数据库还是与 MongoDB 或其他数据库一起使用?

java - 如何序列化 Lucene 查询或将查询转换为字符串并返回查询

php - 2个表单提交相同的数据

mysql - 如何在php中的mysql数据库的一个单元格中存储具有单个名称的多个复选框?