elasticsearch Elasticsearch 7.x映射器[location]无法从类型[geo_point]更改为[text],elasticsearch,elasticsearch" /> elasticsearch Elasticsearch 7.x映射器[location]无法从类型[geo_point]更改为[text],elasticsearch,elasticsearch" />

elasticsearch Elasticsearch 7.x映射器[location]无法从类型[geo_point]更改为[text]

elasticsearch Elasticsearch 7.x映射器[location]无法从类型[geo_point]更改为[text],elasticsearch,elasticsearch,我在elasticsearch中有一个索引,其位置字段映射为一个地理点。这是“索引管理设置”的“映射”选项卡中的内容 { "mappings": { "_doc": { "properties": { "location": { "type": "geo_point" } } }

我在elasticsearch中有一个索引,其位置字段映射为一个地理点。这是“索引管理设置”的“映射”选项卡中的内容

{
  "mappings": {
    "_doc": {
      "properties": {
        "location": {
          "type": "geo_point"
        }
      }
    }
  }
}
根据elasticsearch上的文档,我应该能够将其作为“lat,lon”字符串发送

这是发送给elastic的json中的位置值

'location': '32.807078,-89.908972'
我收到了这个错误消息

RequestError(400, 'illegal_argument_exception', 'mapper [location] cannot be changed from type [geo_point] to [text]')
更新

我能够得到数据流,但现在它来作为文本数据,而不是地理点

这与其他映射一起出现在我的索引映射中

这是在数据中

即使地图在那里,但数据是文本,我无法在地图图表中使用它

解决方案

除了检查答案,还需要这样做

转到主页->管理->Kibana->索引模式


删除了原始索引模式并创建了一个新的索引模式,现在它被视为geo_数据

根据索引映射,您似乎正在使用7.x之前的elasticsearch版本

我使用问题中提供的相同索引映射(使用版本6.8)为文档编制了索引。不要忘记在URL中添加
\u doc
(或在索引映射中使用的类型)(为数据编制索引时)

索引映射:

{
  "mappings": {
    "_doc": {
      "properties": {
        "location": {
          "type": "geo_point"
        }
      }
    }
  }
}
PUT my_index/_doc/1

{
  "location": "41.12,-71.34" 
}
{
  "_index": "65076754",
  "_type": "_doc",
  "_id": "1",
  "_version": 1,
  "result": "created",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 0,
  "_primary_term": 1
}
索引数据:

{
  "mappings": {
    "_doc": {
      "properties": {
        "location": {
          "type": "geo_point"
        }
      }
    }
  }
}
PUT my_index/_doc/1

{
  "location": "41.12,-71.34" 
}
{
  "_index": "65076754",
  "_type": "_doc",
  "_id": "1",
  "_version": 1,
  "result": "created",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 0,
  "_primary_term": 1
}
在向Elasticsearch发布文档时,确保URL的格式如下所述:

{
  "mappings": {
    "_doc": {
      "properties": {
        "location": {
          "type": "geo_point"
        }
      }
    }
  }
}
PUT my_index/_doc/1

{
  "location": "41.12,-71.34" 
}
{
  "_index": "65076754",
  "_type": "_doc",
  "_id": "1",
  "_version": 1,
  "result": "created",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 0,
  "_primary_term": 1
}
响应:

{
  "mappings": {
    "_doc": {
      "properties": {
        "location": {
          "type": "geo_point"
        }
      }
    }
  }
}
PUT my_index/_doc/1

{
  "location": "41.12,-71.34" 
}
{
  "_index": "65076754",
  "_type": "_doc",
  "_id": "1",
  "_version": 1,
  "result": "created",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 0,
  "_primary_term": 1
}
编辑1:

{
  "mappings": {
    "_doc": {
      "properties": {
        "location": {
          "type": "geo_point"
        }
      }
    }
  }
}
PUT my_index/_doc/1

{
  "location": "41.12,-71.34" 
}
{
  "_index": "65076754",
  "_type": "_doc",
  "_id": "1",
  "_version": 1,
  "result": "created",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 0,
  "_primary_term": 1
}
根据下面的评论,OP使用的是7.x

使用7.x索引映射

{
  "mappings": {
    "properties": {
      "location": {
        "type": "geo_point"
      }
    }
  }
}

是的,我正在使用7.x,我正在使用elasticsearch python库。。。也许我拿错版本了。。。我将尝试使用请求库处理PUT请求,请参见。@Four\u 0h\u三如果您使用的是7.x,那么您还需要更改索引映射,因为映射类型已被删除。请阅读本文,了解更多关于删除映射类型@Four\u 0h\u Three的信息,请尝试使用我添加的索引映射再次为文档编制索引。请查看我的更新答案,并让我知道这是否解决了您的问题?我创建了一个新索引,使用put请求添加了映射,与您上面指定的完全相同,我能够接收数据,但它显示为文本,而不是地理数据,我无法在地图图表中使用它。。。一定有什么愚蠢的事情我没有做,我想我只是需要离开这一点,回来与一个新的想法。还有,谢谢你!!!