Elasticsearch:不能过滤多个字段 [英] Elasticsearch: can't filter on multiple fields

查看:334
本文介绍了Elasticsearch:不能过滤多个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'd like to filter a { "query" : { "match_all" :{}}} on elasticsearch but I don't figure it out...

这是我发送到ES _search方法。

Here's what I send to ES _search method.

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"
         }
      }
   ]
}' 

但是我总是收到这个错误:

But I always get this error:

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

如果我删除和:{} 选项,并且只对geo_distance进行过滤,它可以...
任何帮助将是太棒了。

And if I remove the "and" :{} option and only filter on geo_distance, it works... Any help would be fantastic.

干杯

推荐答案

我想你的过滤器未正确写入。该错误指出,过滤器与其参数有差异,或多或少。请参阅 http://www.elasticsearch.org/guide/reference/query -dsl / and-filter /

I think your and filter is incorrectly written. The error states that the and filter is having trouble with its parameters, more or less. See 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"
         }
      }
   ]
}

这篇关于Elasticsearch:不能过滤多个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆