2

我想{ "query" : { "match_all" :{}}}在 elasticsearch 上过滤一个,但我不明白......

这是我发送给 ES _search 方法的内容。

curl -XGET http://localhost:9200/users/location/_search '-H Accept: application/json' '-H Content-Type: application/json'
-d '{
   "query":{
      "match_all":{}
   },
   "filter":{
      "and":{
         "geo_distance":{
            "distance":"500km",
            "location":{
               "lat":48.8,
               "lon":2.33
            }
         },
         "term":{
            "status":1
         }
      }
   },
   "sort":[
      {
         "_geo_distance":{
            "location":[
               2.33,
               48.8
            ],
            "order":"asc",
            "unit":"km"
         }
      }
   ]
}' 

但我总是得到这个错误:

nested: QueryParsingException[[users] [and] filter does not support [distance]]

如果我删除该"and" :{}选项并仅过滤 geo_distance,它就可以工作......任何帮助都会很棒。

干杯

4

1 回答 1

6

我认为你的and过滤器写错了。该错误表明and过滤器的参数或多或少有问题。请参阅http://www.elasticsearch.org/guide/reference/query-dsl/and-filter/

试试这个:

{
   "query":{
      "match_all":{}
   },
   "filter":{
      "and": [
         {
             "geo_distance": {
                "distance":"500km",
                "location":{
                   "lat":48.8,
                   "lon":2.33
                }
             }
         }, {
             "term": {
                "status":1
             }
         }]
      }
   },
   "sort":[
      {
         "_geo_distance":{
            "location":[
               2.33,
               48.8
            ],
            "order":"asc",
            "unit":"km"
         }
      }
   ]
}
于 2013-09-20T20:38:31.140 回答