lqshow / notes

Cheat Sheet
10 stars 2 forks source link

Elasticsearch Mapping #18

Open lqshow opened 6 years ago

lqshow commented 6 years ago

Elasticsearch需要知道每个字段里面都包含什么数据类型。 这些类型和字段的信息存储在映射中创建索引的时候,可以预先定义字段的类型以及相关属性,相当于定义数据库字段的属性

获取映射

查询指定index和type下的映射

curl -XGET 'localhost:9200/{index}/_mapping/{type}?pretty'

获取集群内所有映射信息

curl -XGET 'localhost:9200/_all/_mapping?pretty'

获取集群内多个type映射信息

curl -XGET 'localhost:9200/_all/_mapping/{type1},{type2}?pretty'

结果如下

{
  "gb" : {
    "mappings" : {
      "tweet" : {
        "properties" : {
          "date" : {
            "type" : "date"
          },
          "name" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "tweet" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "user_id" : {
            "type" : "long"
          }
        }
      }
    }
  }
}