为什么这个过滤器查询无效?

时间:2015-04-07 09:49:55

标签: elasticsearch

Elasticsearch版本:

$ curl http://localhost:8086/?pretty
{
  "status" : 200,
  "name" : "Selene",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "1.5.0",
    "build_hash" : "544816042d40151d3ce4ba4f95399d7860dc2e92",
    "build_timestamp" : "2015-03-23T14:30:58Z",
    "build_snapshot" : false,
    "lucene_version" : "4.10.4"
  },
  "tagline" : "You Know, for Search"
}

使用此映射:

$ curl http://localhost:8086/watches/watches/_mapping?pretty
{
  "watches" : {
    "mappings" : {
      "watches" : {
        "properties" : {
          "location" : {
            "type" : "geo_shape",
            "tree_levels" : 5
          },
          "name" : {
            "type" : "string"
          }
        }
      }
    }
  }
}

常规查询很好:

$ curl -XGET -d '
> {
>     "query": {
>         "filtered": {
>             "filter": {
>                 "and": [
>                     {
>                         "geo_shape": {
>                             "location": {
>                                 "shape": {
>                                     "type": "envelope",
>                                     "coordinates": [[-180, 90], [180, -90]]
>                                 }
>                             }
>                         }
>                     }
>                 ]
>             }
>         }
>     }
> }
> ' 'http://localhost:8086/watches/watches/_search?pretty'
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "watches",
      "_type" : "watches",
      "_id" : "berlin",
      "_score" : 1.0,
      "_source":
{
    "name": "Wind & Wetter, Berlin, Germany",
    "location": {
        "type": "Point",
        "coordinates": [13.400544, 52.530286]
    }
}

    } ]
  }
}

注册类似的过滤器查询失败:

$ curl -XPUT -d '
> {
>     "query": {
>         "filtered": {
>             "filter": {
>                 "and": [
>                     {
>                         "geo_shape": {
>                             "location": {
>                                 "shape": {
>                                     "type": "envelope",
>                                     "coordinates": [[-180, 90], [180, -90]]
>                                 }
>                             }
>                         }
>                     }
>                 ]
>             }
>         }
>     }
> }
> ' 'http://localhost:8086/watches/.percolator/mypercolatorquery?pretty'
{
  "error" : "PercolatorException[[watches] failed to parse query [mypercolatorquery]]; nested: QueryParsingException[[watches] Field [location] is not a geo_shape]; ",
  "status" : 500
}

为什么以及如何在过滤器上注册我的查询?

1 个答案:

答案 0 :(得分:0)

事实证明,这是由选项index.percolator.map_unmapped_fields_as_string: true

触发的Elasticsearch中的错误

请参阅问题https://github.com/elastic/elasticsearch/issues/10500