【问题标题】:What exactly does mapping do in Elasticsearch?映射在 Elasticsearch 中究竟做了什么?
【发布时间】: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


【解决方案1】:

什么是映射?
它基本上定义了每个字段的数据类型。 就像在 Mysql 中一样,您为每列定义数据类型。 (整数,浮点数,文本)

什么是动态映射?
你的mysql需要有一个固定的schema。除非预先定义,否则您不能将数据插入列。
Elasticsearch 是无模式的。您可以将数据插入到不存在的字段中
Elasticsearch 会自动为您找出数据类型来创建映射

【讨论】:

    猜你喜欢
    • 2011-06-18
    • 2012-07-23
    • 2016-09-10
    • 2023-03-15
    • 2012-10-17
    • 2021-06-04
    • 1970-01-01
    • 2018-07-30
    • 2019-10-06
    相关资源
    最近更新 更多