使用ElasticSearch的地理距离过滤器始终返回0结果

Sch*_*ike 3 geo elasticsearch

我正在使用带有ElasticSearchGeo Distance Filter,无论我搜索什么距离,elasticsearch 0.90.11都会返回零结果.

这就是我所做的:首先,使用地理映射删除/创建一个新索引:

curl -XDELETE 'http://localhost:9200/photos'

curl -XPOST 'http://localhost:9200/photos' -d '
{
  "mappings": {
    "pin" : {
        "properties" : {
            "location" : {
                "type" : "geo_point"
            }
        }
    }
  }
}
'
Run Code Online (Sandbox Code Playgroud)

然后,添加一个文档:

curl -XPOST 'http://localhost:9200/photos/photo?pretty=1' -d '
{
   "pin" : {
      "location" : {
         "lat" : 46.8,
         "lon" : -71.2
      }
   },
   "file" : "IMG_2115.JPG"
}
'
Run Code Online (Sandbox Code Playgroud)

然后搜索:

curl -XGET 'http://localhost:9200/photos/_search?pretty=1&size=20' -d '
{
   "query" : {
      "match_all" : {}
   },
   "filter" : {
      "geo_distance" : {
         "distance" : "10km",
         "pin.location" : {
            "lat" : "46.8",
            "lon" : "-71.2"
         }
      }
   }
}
'
Run Code Online (Sandbox Code Playgroud)

但搜索产生零点击率:

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}
Run Code Online (Sandbox Code Playgroud)

有人知道为什么它没有在半径范围内找到文件吗?作为一个有趣的附注,如上文所述的文档中描述的具有"查询"和"过滤器"作为子字段的"过滤"语法似乎根本不再起作用,似乎现在"查询"和"过滤器"需要是在json查询的顶级.

任何帮助赞赏...

Sch*_*ike 6

事实证明,官方手册页不准确,需要进行映射

[Sun Feb  9 11:01:55 2014] # Request to: http://localhost:9200
curl -XPUT 'http://localhost:9200/photos?pretty=1' -d '
{
   "mappings" : {
      "photo" : {
         "properties" : {
            "Location" : {
               "type" : "geo_point"
            }
         }
      }
   }
}
'
Run Code Online (Sandbox Code Playgroud)

然后需要添加带有GPS数据的记录,如下所示:

[Sun Feb  9 11:01:56 2014] # Request to: http://localhost:9200
curl -XPOST 'http://localhost:9200/photos/photo?pretty=1' -d '
{
   "file" : "/home/mschilli/iphone/IMG_2115.JPG",
   "Location" : [
      46.8,
      -71.2
   ]
}
'
Run Code Online (Sandbox Code Playgroud)

然后是查询

[Sun Feb  9 11:05:00 2014] # Request to: http://localhost:9200
curl -XGET 'http://localhost:9200/photos/_search?pretty=1&size=100' -d '
{
   "filter" : {
      "geo_distance" : {
         "distance" : "1km",
         "Location" : [
            36.986,
            -121.443333333333
         ]
      }
   },
   "query" : {
      "match_all" : {}
   }
}
'
Run Code Online (Sandbox Code Playgroud)

将显示所需的结果,正确滤除所选GPS距离之外的结果.