当该字段的映射存在时,Elasticsearch“无法找到geo_point字段[location]”

时间:2018-05-27 18:05:04

标签: python elasticsearch elasticsearch-5

我有一个索引,其中包含以下映射:

--ours

我必须使用属性B',因为我的一些文档没有关于它们的位置(纬度/经度)的信息,但我仍然想在一个位置上按距离搜索,参见在这里:https://www.elastic.co/guide/en/elasticsearch/reference/current/null-value.html

检查索引映射详细信息时,我可以验证地理映射是否存在:

--theirs

然而,当尝试使用地理距离过滤器(参见https://www.elastic.co/guide/en/elasticsearch/guide/current/geo-distance.html)搜索该索引上的文档时,我看到了:

C

我认为{ "mappings":{ "my_stuff_type":{ "properties":{ "location": { "type": "geo_point", "null_value": -1 } } } } } 属性应该允许我插入没有null_value字段的文档,同时我应该能够在相同的“可选”字段中使用过滤器进行搜索。

为什么我无法过滤“可选”字段?我怎么能这样做?

修改

要使用python重现此问题,请在从命令行执行curl -XGET http://localhost:9200/my_stuff_index/_mapping | jq '.my_stuff_index.mappings.my_stuff_type.properties.location' { "properties": { "lat": { "type": "float" }, "lon": { "type": "float" } } } / curl -XPOST http://localhost:9200/my_stuff_index/_search -d' { "query": { "bool": { "filter": { "geo_distance": { "location": { "lat": <PUT_LATITUDE_FLOAT_HERE>, "lon": <PUT_LONGITUDE_FLOAT_HERE> }, "distance": "200m" } } } } }' | jq { "error": { "root_cause": [ { "type": "query_shard_exception", "reason": "failed to find geo_point field [location]", "index_uuid": "mO94yEsHQseQDFPkHjM6tA", "index": "my_stuff_index" } ], "type": "search_phase_execution_exception", "reason": "all shards failed", "phase": "query", "grouped": true, "failed_shards": [ { "shard": 0, "index": "my_stuff_index", "node": "MDueSn31TS2z0Lamo64zbw", "reason": { "type": "query_shard_exception", "reason": "failed to find geo_point field [location]", "index_uuid": "mO94yEsHQseQDFPkHjM6tA", "index": "my_stuff_index" } } ], "caused_by": { "type": "query_shard_exception", "reason": "failed to find geo_point field [location]", "index_uuid": "mO94yEsHQseQDFPkHjM6tA", "index": "my_stuff_index" } }, "status": 400 } 操作之前运行以下代码段。

python代码取决于:null_value

location

1 个答案:

答案 0 :(得分:0)

正如@Val所说,你应该改变你的映射。如果以这种方式定义位置字段:

    "location": {
      "type": "geo_point"
    }

您可以将lanlon编入索引作为两个不同的子字段 - 而不是如我所示在映射中声明它们 - 如文档中所述 - look here