mongo-connector旨在将Mongo数据库与另一个目标系统(例如ES,Solr或另一个Mongo
DB)进行同步。同步意味着1:1复制,所以我不知道mongo-connector在复制过程中如何丰富文档(这也不是它的意图)。
但是,在ES
5中,我们很快将能够使用摄取节点,在该节点中,我们将能够定义处理管道,其目的是在文档建立索引之前对其进行充实。
更新
可能有一种修改
formatters.py文件的方法。
在
transform_value我要添加一个案例来处理
Geopoint:
if isinstance(value, dict): return self.format_document(value) elif isinstance(value, list): return [self.transform_value(v) for v in value] # handle Geopoint class elif isinstance(value, Geopoint): return self.format.document({'lat': value['lat'], 'lon': value['lon']}) ...更新2
让我们通过修改
transform_element函数来尝试另一种方法(在第104行):
def transform_element(self, key, value): try: # add these next two lines if key == 'GeoPoint': value = {'lat': value['lat'], 'lon': value['lon']} # do not modify the initial pre below new_value = self.transform_value(value) yield key, new_value except ValueError as e: LOG.warn("Invalid value for key: %s as %s" % (key, str(e)))更新3
您可能要尝试的另一件事是添加一个
transform。我之前没有提到它的原因是它在ES 2.0中已被弃用,但是在ES
5.0中,您将具有摄取节点,并且能够在摄取时使用处理器来
remove处理它
您可以这样定义映射:
PUT my_index2{ "mappings": { "my_type2": { "transform": { "script": "ctx._source.geopoint.remove('alt'); ctx._source.geopoint.remove('valid')" }, "properties": { "geopoint": { "type": "geo_point" } } } }}注意:确保实现动态脚本,加入
script.inline: true到
elasticsearch.yml并重新启动ES节点。
将会发生的是,该
alt字段在存储的字段中仍将是可见的,
_source但不会被索引,因此不会发生任何错误。
使用ES 5,您只需使用
remove处理器创建管道,如下所示:
PUT _ingest/pipeline/geo-pipeline{ "description" : "remove unsupported altitude field", "processors" : [ { "remove" : { "field": "geopoint.alt" } } ]}


