【发布时间】:2020-09-29 17:47:04
【问题描述】:
过去三周我一直在使用 Elasticsearch。我遇到了映射的概念。我已经完成了 RESTful JSON 数据中“lat”和“long”字段的映射。这是我的映射(带有 python 客户端的 ES):
settings = { "settings": {
"number_of_shards":1,
'number_of_replicas':0
},
"mappings" : {
"document" : {
"properties":{
"geo": {
"type": "geo_point"
}
}
}
}
}
es.indices.create(index = "myindex", body=settings)
es.index(index='myindex', doc_type='document', body=new_data)
这将在我的数据中创建一个名为“geo”的新文件。 (如果我错了请纠正我) 但我已经看到它(在某些示例中)如下所示:
settings = { "settings": {
"number_of_shards":1,
'number_of_replicas':0
},
"mappings": {
"document": {
"properties": {
"id": {"type" : "long"},
"version": {"type" : "text"},
"timestamp": {"type" : "long"},
"changeset": {"type" : "long"},
"uid" : {"type" : "long"},
"user_sid" : {"type" : "string"},
"location": {"type": "geo_point"}
}
}
}
}
我不明白它们之间的区别。另外,有些人在谈论动态映射,默认映射让我感到困惑。谁能给我解释一下?
【问题讨论】:
-
映射是您定义字段类型的方式,例如,如果它们是字符串或数字,动态映射基本上是当您不映射您将收到的每个字段并允许弹性搜索进行映射时. documentation 很到位,看看数据类型以及它们之间的区别。
-
定义您的字段类型(int、String 等)以便能够按它们进行搜索。 ES 文档在这方面很棒:elastic.co/guide/en/elasticsearch/reference/6.8/mapping.html
标签: python json elasticsearch