我在elasticsearch中有这个映射
"mappings": {
"properties": {
"fromCoordinates": {"type": "geo_point"},
"toCoordinates": {"type": "geo_point"},
"seenCoordinates": {"type": "geo_point"},
}
}
使用kibana的控制台,geo_ip fields supported by elasticsearch的所有可能组合都没有问题,即:
(纬度,经度)
PUT /anindex/_doc/1
{
"fromCoordinates": {
"lat": 36.857200622558594
"lon": 117.21600341796875,
},
"toCoordinates": {
"lat": 22.639299392700195
"lon": 113.81099700927734,
},
"seenCoordinates": {
"lat": 36.91663
"lon": 117.216,
}
}
(lon,lat)
PUT /anindex/_doc/2
{
"fromCoordinates": [36.857200622558594, 117.21600341796875],
"toCoordinates": [22.639299392700195, 113.81099700927734],
"seenCoordinates": [36.91663, 117.216]
}
但是我尝试通过python将数据插入elasticsearch,并且我总是遇到这个错误:
RequestError(400, 'illegal_argument_exception', 'mapper [fromCoordinates] of different type, current_type [geo_point], merged_type [ObjectMapper]')
在python中,我从字典构造json,这是我打印时的结果:
fromCoordinates = {}
fromCoordinates['lat'] = fromLat
fromCoordinates['lon'] = fromLon
dataDictionary.update({'fromCoordinates': fromCoordinates , 'toCoordinates': toCoordinates, 'seenCoordinates': seenCoordinates})
print(json.dumps(dataDictionary).encode('utf-8'))
{"fromCoordinates": {"lat": 43.9962005615, "lon": 125.684997559},
"toCoordinates": {"lat": 40.080101013183594, "lon": 116.58499908447266},
"seenCoordinates": {"lat": 33.62672, "lon": 109.37243}}
并加载与此
data = json.dumps(dataDictionary).encode('utf-8')
es.create(index='anindex', doc_type='document', id=0, body=data)
阵列版本具有相同的问题:
fromCoordinates = [fromLon, fromLat]
这是在python中创建并打印的json:
{"fromCoordinates": [113.81099700927734, 22.639299392700195],
"toCoordinates": [106.8010025024414, 26.53849983215332],
"seenCoordinates": [107.46743, 26.34169]}
在这种情况下,我有此回应
RequestError: RequestError(400, 'mapper_parsing_exception', 'geo_point expected')
如果我尝试使用StreamSets进行elasticsearch,则会出现相同的错误,并且之前显示了两种json类型:
mapper [fromCoordinates] of different type, current_type [geo_point], merged_type [ObjectMapper]
有任何想法吗?
更新:
GET /anindex/_mapping
{ "anindex" :
{ "mappings" :
{ "properties" :
{ "fromCoordinates" :
{ "type" : "geo_point" },
"toCoordinates" :
{ "type" : "geo_point" },
"seenCoordinates" : { "type" : "geo_point" }
}
}
}
}
解决方案:
在@jzzfs给出的示例之后,我意识到
es.create(index='anindex', doc_type='document', id=0, body=data)
中的doc_type参数引起了错误,我将其删除了,并且它起作用了.....但是我仍然想知道为什么StreamSets中存在相同的错误...但是我` ll继续使用python。
最佳答案
如果您使用的是Elasticsearch的旧版本(例如6.1)并已升级到较新的版本(例如7.X),则需要在索引模式中删除doc_type,因为新版本不再接受该对象。
旧索引模式
res=es_local.index(index='local-index',doc_type='resource', body=open_doc,id=_id,request_timeout=60)
新的索引模式
res=es_local.index(index='local-index', body=open_doc,id=_id,request_timeout=60)
注意:-在新的索引模式中没有doc_type(假定使用python进行索引)。
关于python - geo_point映射python和StreamSets随Elasticsearch失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61268424/