gpt4 book ai didi

python - 当该字段存在映射时,Elasticsearch “failed to find geo_point field [location]”

转载 作者:行者123 更新时间:2023-12-02 22:36:33 25 4
gpt4 key购买 nike

我有一个具有以下映射的索引:

{
"mappings":{
"my_stuff_type":{
"properties":{
"location": {
"type": "geo_point",
"null_value": -1
}
}
}
}
}

我必须使用 null_value属性,因为我的某些文档没有有关其位置(纬度/经度)的信息,但是我仍然想按位置上的距离进行搜索,请参见。这里: https://www.elastic.co/guide/en/elasticsearch/reference/current/null-value.html

在检查索引映射详细信息时,我可以验证是否存在地理映射:
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"
}
}
}

但是,当尝试使用地理距离过滤器(参见 https://www.elastic.co/guide/en/elasticsearch/guide/current/geo-distance.html)在该索引上搜索文档时,我看到以下内容:
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
}

我认为 null_value属性应该允许我插入文件而无需提交 location,同时我应该能够在同一“可选”字段中使用过滤器进行搜索。

为什么我无法过滤该“可选”字段?我该怎么办?

编辑:

要使用python重现此问题,请在从命令行执行 curl / jq操作之前,运行以下代码段。

python代码取决于此: pip install elasticsearch==5.4.0
from elasticsearch import Elasticsearch
from elasticsearch import helpers

my_docs = [
{"xyz": "foo", "location": {"lat": 0.0, "lon": 0.0}},
{"xyz": "bar", "location": {"lat": 50.0, "lon": 50.0}}
]

es = Elasticsearch([{'host': 'localhost', 'port': 9200}])

index_mapping = '''
{
"mappings":{
"my_stuff_type":{
"properties":{
"location": {
"type": "geo_point",
"null_value": -1.0
}
}
}
}
}'''

es.indices.create(index='my_stuff_index', ignore=400, body=index_mapping)

helpers.bulk(es, my_docs, index='my_stuff_index', doc_type='my_stuff_type')

最佳答案

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

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

您可以将 lanlon索引为两个不同的子字段-无需按我显示的那样在映射中声明它们-如文档中所述- look here

关于python - 当该字段存在映射时,Elasticsearch “failed to find geo_point field [location]”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50555037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com