2

I would like to run an elasticsearch query to find items within 10mi of a given point.

I know how to do it with a post, but I would like to use a get with everything in the uri.

I found the below example but it does not work.

http://localhost:9200/items/item/_search?{%22query%22:{%22filtered%22:{%22query%22:{%22match_all%22:{}},%22filter%22:{%22geo_distance%22:{%22distance%22:%220.1km%22,%22location%22:{%22lat%22:46.884106,%22lon%22:-71.377042}}}}}}

Any way to do this or am I stuck using a post?

4

1 回答 1

3

关键是source=参数。不要与 _source 混淆。

http://localhost:9200/items/item/_search?source={%22query%22:{%22filtered%22:{%22query%22:{%22match_all%22:{}},%22filter%22:{%22geo_distance%22:{%22distance%22:%220.1km%22,%22location%22:{%22lat%22:46.884106,%22lon%22:-71.377042}}}}}}

我试过 ?q= 和http://www.elasticsearch.org/guide/reference/api/search/uri-request/上列出的一些其他参数,但没有运气(源未列出)。

我找到了http://www.elasticsearch.org/guide/reference/api/并在最底部说

查询字符串中的请求正文

对于不接受非 POST 请求的请求正文的库,您可以将请求正文作为源查询字符串参数传递。

因此,构建您的查询/过滤请求,将其全部设置在一行上并将其发送到源参数中。

不要将 q= 参数与 source= 一起使用,否则它会发生冲突并破坏查询,但是我尝试了 size= 和 from= 并且它们与 source 一起工作得很好。

于 2013-08-09T20:59:55.150 回答