Elasticsearch:无法过滤多个字段

时间:2013-09-20 16:48:55

标签: elasticsearch

我想在弹性搜索中过滤{ "query" : { "match_all" :{}}},但我不明白......

这是我发送给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,则可以正常工作...... 任何帮助都会很棒。

干杯

1 个答案:

答案 0 :(得分: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"
         }
      }
   ]
}