RequestError(400,'parse_exception','create index'的未知键[属性])

2024-06-01 21:24:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用python创建一个elasticsearch索引,其内容是一系列坐标,以便以后在kibana地图中可视化这些数据

不幸的是,我收到了以下错误消息:

RequestError(400, 'parse_exception', 'unknown key [properties] for create index')

这是我正在使用的代码:

es = Elasticsearch()

mappings = {
       "properties": {
            "geo": {
                "properties": {
                     "location": {
                         "type": "geo_point"
                 }
            }
        }
     } 
 }
 
es.indices.create(index='geodata', body=mappings)
es_entries['geo']={ 'location': str(coor[0])+","+str(coor[1])}
es.index(index='geodata', doc_type="doc", body=es_entries)    

Tags: indexdocestypecreatebodylocationproperties
1条回答
网友
1楼 · 发布于 2024-06-01 21:24:15

到目前为止做得很好,你就快到了。需要做一些更改:

    mappings = {
       "mappings": {                      < - add this
           "properties": {
                "geo": {
                    "properties": {
                         "location": {
                             "type": "geo_point"
                         }
                     }
                }
            }
         }
     }
     
    es.indices.create(index='geodata', body=mappings)
    es_entries['geo']={ 'location': str(coor[0])+","+str(coor[1])}
    es.index(index='geodata', doc_type="_doc", body=es_entries)    
                                        ^
                                        |
                                   modify this

相关问题 更多 >